Back
I have a double in Java and I want to check if it is NaN. What is the best way to do this?
NaN
Try the static Double.isNaN(double) way, or your Double's .isNaN() method.
// 1. static methodif (Double.isNaN(doubleValue)) {...}// 2. object's methodif (doubleObject.isNaN()) {...}
// 1. static method
if (Double.isNaN(doubleValue)) {
...
}
// 2. object's method
if (doubleObject.isNaN()) {
By Easily trying:
if (var == Double.NaN) {...}
if (var == Double.NaN) {
is not sufficient due to how the IEEE standard for NaN and floating-point numbers are defined.
31k questions
32.8k answers
501 comments
693 users