Jordn
Jordn

Reputation: 35

Smaller than or bigger than shows wrong result

I have this small piece of code:

if(parseFloat(400).toFixed(2) < parseFloat(21233).toFixed(2)){
//Cant Do It
} else {
//Can Do It
}

How it makes sense? 400 IS smaller than 21233, but regarding to this code it isn't like this. Why?

Upvotes: 0

Views: 28

Answers (1)

Halcyon
Halcyon

Reputation: 57709

toFixed() outputs a string so you're comparing:

"400.00" < "21233.00"

Which is false because "4" is not less than "2".

Upvotes: 1

Related Questions