wwwroth
wwwroth

Reputation: 434

Logic and floats, 0.75 > 0 = false?

In Javascript I have an if statement that is failing that should be passing and I cannot figure out why. Here's the structure of the if.

if(parseInt(obj.OptionCredit) > parseInt(Account.Credits))
{
     true
}
else

{
     false
}

When I console log the two variables I get Account.Credits = 0 and obj.OptionCredit = 0.75. With that said, 0.75 > 0 should return false.

Can anyone help me out with this? Thank you!

Upvotes: 0

Views: 96

Answers (2)

Mark Walters
Mark Walters

Reputation: 12390

You need to use parseFloat() instead of parseInt()

Upvotes: 1

TomD
TomD

Reputation: 166

You are parsing them as ints (not floats), so they both return zero. 0 is not greater than 0, so the comparison returns false.

Upvotes: 3

Related Questions