How to Tell If a Double Number Is NaN in Java


In this example we will show how to tell if a double number is NaN use the isNaN() method of the Double class in Java.

Source Code

package com.beginner.examples;

public class DoubleIsNaNExamples {

	public static void main(String[] args) {

		Double double1 = new Double(Math.sqrt(-1));

		// Use the isNaN() method to determine
		System.out.println(double1.isNaN());

	}

}

Output:

true
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments