Java Program to convert String to Primitive Float
Apr 22, 2024
Make sure to subscribe to our newsletter and be the first to know the news.
Apr 22, 2024
Make sure to subscribe to our newsletter and be the first to know the news.
1)String Initialization:A String variable s is initialized with the value "59", which represents the string representation of a number.
2)Parsing String to Float:The parseFloat() method of the Float class is utilized to parse the String s into a float value f. This method converts the string representation of a floating-point number into a float primitive.
3)Output:The program prints the float value f along with a descriptive label "Float ".
public class StringToPrimitive {
public static void main(String[] args) {
String s="59";
float f=Float.parseFloat(s);
System.out.println("Float "+f);
}
}