Why does Python report 0.1 + 0.2 == 0.3 as false?
0.1 has no exact binary form, so it is stored as a close approximation.
- A bug in the processor
- The language rounds to 2 places
- 0.1 cannot be stored exactly in binary ✔
Why: Computers store floats as binary fractions. Just like 1/3 never ends in decimal, 1/10 never ends in binary. The tiny rounding errors in 0.1 and 0.2 add up, so the sum is 0.30000000000000004.
Huh, didn't know that: Python's docs note this is not a Python bug: the same thing happens in every language that uses your hardware's floating point.
Why did 0.1 and 0.2 break up? They just didn't add up.
References
Answer: 0.1 cannot be stored exactly in binary. Computers store floats as binary fractions. Just like 1/3 never ends in decimal, 1/10 never ends in binary. The tiny rounding errors in 0.1 and 0.2 add up, so the sum is 0.30000000000000004.
- Python docs: Floating-Point Arithmetic, Issues and Limitations docs.python.org/3/tutorial/floatingpoint.html
no matter how many base 2 digits you're willing to use, the decimal value 0.1 cannot be represented exactly as a base 2 fraction
Checked 2026-10-10.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.