+ 1

Why aren't floats precise

When i typed 0.1 * 3 in the python shell i got something like 0.3000000004 but why did i get that as outcome and not just 0.3?

23rd Aug 2017, 9:16 PM
Joel Burleson
Joel Burleson - avatar
1 Antwort
+ 5
That occurs because floating-point numers are stored as binary numbers , and you can't precisely store 0.1(binary: 0.000110011001100...) in binary , just like you cant store 1/3 (decimal: 0.33333333333.....) precisely in the decimal system
23rd Aug 2017, 9:22 PM
abseabsmeier
abseabsmeier - avatar