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:
public class gfg {
public static void main(String[] args)
{
Integer x = new Integer( 1785423456 );
System.out.println(x.floatValue());
Double y = new Double( 97854876 );
System.out.println(y.floatValue());
}
}
|
Output:
1.78542349E9
9.785488E7
Program 2:
public class gfg {
public static void main(String[] args)
{
Integer x = new Integer( 456 );
System.out.println(x.floatValue());
Double y = new Double( 96 );
System.out.println(y.floatValue());
}
}
|