+ 3
Any one can help me why >> .1 *3 = 0.30000000000000004 when executed in python not .3?
Please feedback
3 odpowiedzi
+ 10
It's in every language that uses standard floating-point arithmetic. Computers can't store some decimals (floating-points) perfectly, like how we can't store 0.333333333... perfectly in our number system. In binary, 0.1 is one of those repeating decimals.
It's quite an interesting topic, actually. I'd suggest reading more if you're interested.
+ 5
Since computers use binary number system instead of decimal, they lose some precision while operating with floats and doubles because 0.1 in decimal will be 0.0001111.... in binary system, i.e., it loses some precision while converting from decimal to binary.
Just like LunarCoffee said, it is difficult to store 0.3333333..... perfectly in decimal system, likewise, 0.1 is not in binary. If you store 0.33333..... in base-3 format, it would store perfectly as 0.1 in that base.
+ 2
it's the precision