views:

102

answers:

1

I'm sure this is a simple problem, but I'm comparing negative numbers in javascript i.e.:

var num1 = -83.778;
var num2 = -83.356;

if(num1 < num2)
{
    // Take action 1
}
else
{
    // Take action 2
}

This script will always take action 2, even though num1 is less than num2. Whats going on here?

+1  A: 

How does if (parseFloat(num1) < parseFloat(num2)) work? Maybe you're numbers are turning into strings somewhere.

Seth
exactly. I was getting the numbers from a JSON response and not parsing them back into floats.Haha sorry everyone....
Tom G