in Javascript I can't seem to find a method to set negatives to zero?
-90 becomes 0
-45 becomes 0
0 becomes 0
90 becomes 90
Is there anything like that? I have just rounded numbers.
in Javascript I can't seem to find a method to set negatives to zero?
-90 becomes 0
-45 becomes 0
0 becomes 0
90 becomes 90
Is there anything like that? I have just rounded numbers.
On
Remember the negative zero.
function isNegativeFails(n) {
return n < 0;
}
function isNegative(n) {
return ((n = +n) || 1 / n) < 0;
}
isNegativeFails(-0); // false
isNegative(-0); // true
Math.max(-0, 0); // 0
Math.min(-0, 0); // -0
Source: http://cwestblog.com/2014/02/25/javascript-testing-for-negative-zero/
Just do something like
or
or