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
Asked
Active
Viewed 54 times
0

Denny John
- 464
- 7
- 20

Fedor Petrenko
- 33
- 7
-
[Detailed explanation](https://stackoverflow.com/a/21895757/540352) – Laoujin Jun 12 '17 at 09:28
-
Possible duplicate of [Why Are Floating Point Numbers Inaccurate?](https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate) – Christopher Moore Jun 12 '17 at 10:27
2 Answers
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