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 ?
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var temp="-2"
var tempIsNegative = !(temp == Math.abs(temp)); // true or false
var tempIsNegative = !(temp == Math.abs(temp)); // true or false
then you will get absolute..