Float isNaN() method in Java with examples Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The Float.isNaN() method in Float Class is a built in method in Java returns true if this Float value or the specified float value is Not-a-Number (NaN), or false otherwise. Syntax: public boolean isNaN() or public static boolean isNaN(float val) Parameters: he function accepts a single parameter val which specifies the value to be checked when called directly with the Float class as static method. The parameter is not required when the method is used as instance method. Return Value: It returns true if the val is NaN else it return false. Below programs illustrate isNaN() method in Java: Program 1: Using static isNaN() method Java // Java code to demonstrate // Float isNaN() method // without parameter class GFG { public static void main(String[] args) { // first example Float f1 = new Float(1.0 / 0.0); boolean res = f1.isNaN(); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); // second example f1 = new Float(0.0 / 0.0); res = f1.isNaN(); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); } } Output: Infinity is not NaN NaN is NaN Program 2: Using non-static isNaN() method Java // Java code to demonstrate // Float isNaN() method // with parameter class GFG { public static void main(String[] args) { // first example Float f1 = new Float(1.0 / 0.0); boolean res = f1.isNaN(f1); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); // second example f1 = new Float(0.0 / 0.0); res = f1.isNaN(f1); // printing the output if (res) System.out.println(f1 + " is NaN"); else System.out.println(f1 + " is not NaN"); } } Output: Infinity is not NaN NaN is NaN Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#isNaN() Comment More infoAdvertise with us Next Article Float floatToIntBits() method in Java with examples G gopaldave Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions Java-Float +1 More Practice Tags : Java Similar Reads 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 ill 2 min read Double isNaN() method in Java with examples The isNaN() method of Java Double class is a built in method in Java returns true if this Double value or the specified double value is Not-a-Number (NaN), or false otherwise. Syntax: public boolean isNaN() or public static boolean isNaN(double val) Parameters: The function accepts a single paramete 2 min read Float floatToIntBits() method in Java with examples The floatToIntBits() method in Float Class is a built-in function in java that returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout. Syntax: public static int floatToIntBits(float val) Parameter: The method accepts only on 2 min read Float compare() Method in Java with Examples The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. Syntax: public static int compare(float f1, float f2)Parameters: The f 2 min read Java floor() method with Examples The java.lang.Math.floor() returns the double value that is less than or equal to the argument and is equal to the nearest mathematical integer. Note: If the argument is Integer, then the result is Integer.If the argument is NaN or an infinity or positive zero or negative zero, then the result is th 2 min read Float byteValue() method in Java with Examples The java.lang.Float.byteValue() is a built-in method in Java that returns the value of this Float as a byte(by casting to a byte). Basically it used for narrowing primitive conversion of Float type to a byte value. Syntax: public byte byteValue() Parameters: The function does not accept any paramete 2 min read Like