Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for NaN, null and >=0 in one condition

I have a var a;

Its value can be NaN, null and any +ve/-ve number including 0.

I require a condition which filters out all the values of a such that only >=0 values yield a true in if condition.

What is the best possible way to achieve this, I do not wish to use 3 different conditions joined using ||

like image 816
Bhumi Singhal Avatar asked May 10 '13 07:05

Bhumi Singhal


People also ask

How do you test against NaN?

1. isNaN() Method: To determine whether a number is NaN, we can use the isNaN() function. It is a boolean function that returns true if a number is NaN otherwise returns false.

Does NaN equal null?

Within pandas, a missing value is denoted by NaN . In most cases, the terms missing and null are interchangeable, but to abide by the standards of pandas, we'll continue using missing throughout this tutorial.

Is NaN null or undefined?

NaN values are generated when arithmetic operations result in undefined or unrepresentable values.

How do you check if a return value is a NaN?

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.


1 Answers

Ohk ...But i actually found the ans .. it is so Simple .

parseInt(null) = NaN.

So if(parseInt(a)>=0){} would do ...Yayyee

like image 197
Bhumi Singhal Avatar answered Oct 29 '22 23:10

Bhumi Singhal