In this tutorial we will learn how to convert a string type data to float type data.
In this tutorial we will learn how to convert a string type data to float type data.In this tutorial we will learn how to convert a string type data to float type data.
This program will take a String value from mystring variable. The line float myfloat = Float.parseFloat(mystring); converts the mystring string type value to myfloat float type value. The parseFloat() method coverts the any type data to float type data.
class Stringtofloat {
public static void main(String[] args) {
try {
String mystring = "1.4";
float myfloat = Float.parseFloat(mystring);
System.out.println("Converted value from String to float is: "
+ myfloat);
} catch (Exception e) {
System.out.println(" Error " + e);
}
}
};
