Comparing negative numbers in javascript

I am sure this is a simple problem, but I am comparing negative numbers in javascript ie:

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, although num1 less than num2 . What is going on here?

+6
javascript comparison numbers
source share
1 answer

How does if (parseFloat(num1) < parseFloat(num2)) ? Maybe you numbers turn into strings somewhere.

+12
source share

All Articles