Fedor Petrenko
Fedor Petrenko

Reputation: 33

Wrong result in console

When I try to calculate 700*0.7 in my code the result gets wrong. Console shows 489.99999999999994 eventhough the correct result is 490. I really don't understood what the magic is this. Can anyone clarify it? Other numbers are calculated normally. P.S. U can try this in console chrome. example1

example2

Upvotes: 0

Views: 59

Answers (2)

Manu
Manu

Reputation: 10964

Floating point arithmetic is not always 100% accurate. Use the standard Math library functions to be 100% sure of the results when dealing with floating numbers.

Upvotes: 0

Jonathan Petitcolas
Jonathan Petitcolas

Reputation: 4574

That's some floating numbers issue: http://floating-point-gui.de/

Just round the result, and it should be good. :)

Upvotes: 1

Related Questions