The intValue() method in Float Class is a built in method in Java that returns the value specified by the calling object as int after type casting.
Syntax:
public int intValue()
Parameters: The function accepts no parameter.
Return Value: It return the value of FloatObject as int.
Below programs illustrate intValue() method in Java:
Program 1:
class GFG {
public static void main(String[] args)
{
Float a = 17 .47f;
Float b = new Float(a);
int output = b.intValue();
System.out.println( "Int value of "
+ b + " is : " + output);
}
}
|
Output:
Int value of 17.47 is : 17
Program 2:
class GFG {
public static void main(String[] args)
{
Float a = Float.NaN;
Float b = new Float(a);
int output = b.intValue();
System.out.println( "Int value of "
+ b + " is : " + output);
}
}
|
Output:
Int value of NaN is : 0
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#intValue()