How to convert String to Float in Java
Example of converting String to Float in Java

* Convert String to Float example. Program to convert Java
* String object to Float object.

public class StringToFloat {

public static void main(String args[]){

//new String object
String str = new String("15.43");

//Use Float(String) constructor
Float fObj1 = new Float(str);

//OR Use static valueOf(String) method of Float class
Float fObj2 = Float.valueOf(str); //throws NumberFormatException

System.out.println("String converted to Float: " + fObj1);


Ads by Google

String converted to Float: 15.43
String Examples