I’m sure this is a simple problem, but I’m comparing negative numbers in javascript i.e.:
JavaScript
x
12
12
1
var num1 = -83.778;
2
var num2 = -83.356;
3
4
if(num1 < num2)
5
{
6
// Take action 1
7
}
8
else
9
{
10
// Take action 2
11
}
12
This script will always take action 2, even though num1
is less than num2
. Whats going on here?
Advertisement
Answer
How does if (parseFloat(num1) < parseFloat(num2))
work? Maybe your numbers are turning into strings somewhere.