What is Double.isNan() in Java?

Overview

The isNaN() method of the Java Double class returns true if the specified number is a NaN (Not-a-Number) value. Otherwise, it returns false.

Double is defined in the lang package in Java.

Method Signature

public static boolean isNaN(double v)

Parameters

double v: the value to be tested.

Example

In the code below, we define three different double variables, each the result of a different computation. Then, we use the isNaN() method of Double class to test the result for NaN.

import java.lang.Double;
public class Main {
public static void main(String args[])
{
Double d1 = 100 / 0.0;
Double d2 = 0 - 0.0;
Double d3 = 100 * 0 / 0.0;
System.out.println(d1 +" - " + d1.isNaN());
System.out.println(d2 +" - " + d2.isNaN());
System.out.println(d3 +" - " + d3.isNaN());
}
}

Free Resources