0

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

Denny John
  • 464
  • 7
  • 19

2 Answers2

1

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

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

Jonathan Petitcolas
  • 3,978
  • 4
  • 27
  • 41
0

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.

Peter
  • 9,437
  • 14
  • 79
  • 120