//Java code to convert String to Float
public class Main {
public static void main(String args[]) {
String str = "1234.587878f";
//variable to store result
float result = 0;
//converting string to Float
//method 1
result = Float.valueOf(str).floatValue();
System.out.println("result (value of str as float) = " + result);
//method 2
result = Float.parseFloat(str);
System.out.println("result (value of str as float) = " + result);
}
}
Output
result (value of str as float) = 1234.5879
result (value of str as float) = 1234.5879
Java code to convert a String to Float
Output