Skip to content
Advertisement

Comparing negative numbers in javascript

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

JavaScript

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.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement