The java.lang.Number.floatValue() is an inbuilt method in java that returns the value of the specified number casted to float data type. This may involve rounding or truncation.
Syntax:
public abstract float floatValue()
Parameters: This method does not accepts any parameter.
Returns: This method returns the numeric value represented by this object after conversion to type float.
Below programs illustrate the Number.floatValue() method:
Program 1:
// Below program demonstrate the // Number.floatValue() method public class gfg {
public static void main(String[] args)
{
// number with integer datatype
Integer x = new Integer( 1785423456 );
// print the value as float
System.out.println(x.floatValue());
// number with double datatype
Double y = new Double( 97854876 );
// print the value as float
System.out.println(y.floatValue());
}
} |
Output:
1.78542349E9 9.785488E7
Program 2:
// Below program demonstrate the // Number.floatValue() method public class gfg {
public static void main(String[] args)
{
// number with integer datatype
Integer x = new Integer( 456 );
// print the value as float
System.out.println(x.floatValue());
// number with double datatype
Double y = new Double( 96 );
// print the value as float
System.out.println(y.floatValue());
}
} |
Output:
456.0 96.0