Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test for NaN? [duplicate]

Possible Duplicate:
Comparing NaN values for equality in Javascript

Can anyone tell me why this is not working?

if(inbperr == NaN) {     document.getElementById('inbclo').value = "N/A"; } else {     document.getElementById('inbclo').value = "%" + inbperr; } 

Instead of returning a percentage value, or "N/A", I want it to return "%NaN".

like image 762
I wrestled a bear once. Avatar asked Jul 06 '12 00:07

I wrestled a bear once.


People also ask

How do you test for NaN?

Check for NaN with self-equality In JavaScript, the best way to check for NaN is by checking for self-equality using either of the built-in equality operators, == or === . Because NaN is not equal to itself, NaN != NaN will always return true .

How do you match NaN in Python?

The math. isnan() method checks whether a value is NaN (Not a Number), or not. This method returns True if the specified value is a NaN, otherwise it returns False.

Why is NaN a float Python?

In data science, Nan is used to represent the missing values in a dataset. So Nan is basically a placeholder to represent undefined or missing values. You can create the Nan value using float type. Since it is not a defined keyword in Python, you have to pass it to float in a string format (within quotes).

What does NaN mean in Python?

NaN stands for Not A Number and is a common missing data representation. It is a special floating-point value and cannot be converted to any other type than float.


1 Answers

NaN's are unusual: they are not equal to anything, even themselves. You need to use isNaN(inbperr) to tell whether a value is a NaN or not.

like image 121
Ned Batchelder Avatar answered Sep 29 '22 12:09

Ned Batchelder