languages/why-does-0-1-0-2-give-0-30000000000000004-in-python.md

Why does 0.1 + 0.2 give 0.30000000000000004 in Python?

Programming languages · 4 min read ·

Type 0.1 + 0.2 into Python and you get 0.30000000000000004. It is not a bug: computers store fractions in binary, and one tenth has no exact binary form, just as one third has no exact decimal form.

Try the live tool to see the exact value your computer stores, its 64 bits, and the rounding step that creates the odd answer.