Float floatValue() in Java with examples
Last Updated :
19 Nov, 2020
The floatValue() method in Float Class is a built-in function in java that returns the value specified by the calling object as float after type casting.
Syntax:
public float floatValue()
Return Value: It returns the value of FloatObject as float.
Below programs illustrate floatValue() method in Java:
Program 1:
Java
class GFG {
public static void main(String[] args)
{
Float a = 17 .47f;
Float b = new Float(a);
float output = b.floatValue();
System.out.println( "Float value of "
+ b + " is : " + output);
}
}
|
Output:
Float value of 17.47 is : 17.47
Program 2:
Java
class GFG {
public static void main(String[] args)
{
String value = "54.1" ;
Float b = new Float(value);
float output = b.floatValue();
System.out.println( "Float value of "
+ b + " is : " + output);
}
}
|
Output:
Float value of 54.1 is : 54.1
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#floatValue()
Share your thoughts in the comments
Please Login to comment...