Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

how do I check the sign of a java script variable ?

how do I check the sign of a java script variable ?

Here is my input/output to illustrate the problem.

Example Input/output:
Input:  var temp="-2"
Output:  This is a negative number . absolute value is =2

Input:  var temp="2"
Output:  This is a positive number . absolute value is 2

Input:  var temp="0"
Output:  This is a zero . absolute value is 0

I'm worried as javascript variable are unsigned . How do I check for a negative number then like above ?
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

check if it less than 0, then multiply by -1
then you will get absolute..
ASKER CERTIFIED SOLUTION
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leakim971
var temp="-2"
var tempIsNegative = !(temp == Math.abs(temp)); // true or false