+ 1
Why 0.1+0.2 is not 0.3 in javascript ?
Why 0.1+0.2 is not 0.3 in javascript ?
3 Respostas
+ 4
Floating point rounding errors. 0.1 cannot be represented as accurately in base-2 as in base-10 due to the missing prime factor of 5. Just as 1/3 takes an infinite number of digits to represent in decimal, but is "0.1" in base-3, 0.1 takes an infinite number of digits in base-2 where it does not in base-10. And computers don't have an infinite amount of memory.
+ 3
Yeah, to get 0.3 you actually have to do (0.1 * 10 + 0.2 * 10) / 10
+ 1
It's caused by the way of numbers are stored internaly by JS.
Detailled explications there: http://www.w3schools.com/js/js_numbers.asp