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
  • 20

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
  • 4,254
  • 4
  • 31
  • 42
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
  • 10,492
  • 21
  • 82
  • 132