Why do I sometimes see long decimal numbers?
Why results like 3.8999999999 appear instead of 3.9, and how floating-point storage causes it.
Why do I sometimes see long decimal numbers like 3.8999999999 instead of a neat 3.9?
This happens because computers store numbers in binary (base 2), not in decimal (base 10). Some decimal fractions that look simple to us cannot be represented exactly in binary. For example, just as 1/3 cannot be written exactly in decimal (it becomes 0.3333…), the decimal 28.9 cannot be stored exactly in binary. (See IEEE Standard for Floating-Point Arithmetic for more information).
When you subtract 25 from 28.9, the computer is actually doing the calculation with a tiny approximation of 28.9. That’s why you may see a result like 3.8999999999 instead of the neatly rounded 3.9.
What does this mean for me?
The small differences are normal and expected in all programming languages (including Python). When needed, you can round them to a fixed number of decimal places (e.g. round(28.9 - 25, 2) → 3.89).
Last modified on July 23, 2026