Thursday, December 11, 2025
HomeLanguagesJavaFloat intValue() method in Java with examples

Float intValue() method in Java with examples

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:




// Java code to demonstrate
// Float intValue() method
class GFG {
    public static void main(String[] args)
    {
  
        // Float value
        Float a = 17.47f;
  
        // wrapping the Float value
        // in the wrapper class Float
        Float b = new Float(a);
  
        // intValue of the Float Object
        int output = b.intValue();
  
        // printing the output
        System.out.println("Int value of "
                           + b + " is : " + output);
    }
}


Output:

Int value of 17.47 is : 17

Program 2:




// Java code to demonstrate
// Float intValue() method
// Not a number
class GFG {
    public static void main(String[] args)
    {
  
        // Float value
        Float a = Float.NaN;
  
        // wrapping the Float value
        // in the wrapper class Float
        Float b = new Float(a);
  
        // intValue of the Float Object
        int output = b.intValue();
  
        // printing the output
        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()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6942 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS