public class StringToFloatExample {
public static void main(String[] args) {
String str = "3.14";
float floatValue = Float.parseFloat(str);
System.out.println("Float value: " + floatValue);
}
}
In this example, the parseFloat() method from the Float class is used to convert the String representation of a number to a float value. The converted float value is then assigned to the floatValue variable. Finally, the value is printed to the console using System.out.println().
No comments:
Post a Comment