Recommended Free Tools
In Python’s common IEEE 754 binary64 case, the computer stores nearby binary values for 0.1 and 0.2, not the exact decimal fractions. It adds those stored values, rounds the result to the floating-point format, and displays it as 0.30000000000000004. That is expected finite-precision behavior—not broken addition.
Why can’t a binary float store 0.1 exactly?
Binary fractions are sums of powers of two. A reduced fraction terminates in binary only when its denominator contains no prime factors other than 2. But one tenth is 1/10, whose denominator includes a factor of 5, so its binary expansion repeats without ending. A finite floating-point format must stop that expansion and use a nearby representable value.
As an Amazon Associate I earn from qualifying purchases.
On platforms where Python’s float uses IEEE 754 binary64—the behavior documented for almost all platforms—the format has 53 bits of precision. Python’s documentation gives the exact rational value for the float nearest to 0.1 as 3602879701896397 / 2**55. Its exact decimal value is 0.1000000000000000055511151231257827021181583404541015625, slightly greater than one tenth. This is the value represented by that float, not an exact decimal tenth. Python’s floating-point tutorial
Free tools Windows power users keep installed
One-click scans. No signup required.
What happens when the computer adds 0.1 and 0.2?
- Each decimal literal is converted. The text
0.1and0.2is parsed into nearby representable binary64 values; neither decimal fraction has a finite binary expansion. - The represented values are added. The operation uses those stored approximations, not the ideal mathematical values 1/10 and 2/10.
- The sum is rounded to the destination format. The exact sum of the two represented inputs may itself not be representable, so the result is rounded to a nearby floating-point value.
- The result is formatted for display. Python commonly prints
0.30000000000000004. Those digits are generated decimal text, not decimal characters stored inside the float.
The important distinction is that input conversion, arithmetic rounding, and output formatting are separate stages. IEEE 754 floating point represents numbers in a binary format; the mismatch arises when a decimal fraction has no finite representation in that format. For background on floating-point rounding, see David Goldberg’s paper on floating-point arithmetic.
#1 Best Overall
Why does Python sometimes print just 0.1?
Many decimal strings can convert to the same floating-point value. Python chooses a short representation that, when parsed again, reconstructs that same value. So displaying 0.1 is a convenient round-trip label; it does not mean the stored value equals exactly 1/10. Formatting changes how a value looks, not the value held in memory. Python’s tutorial explains this display behavior.
When should you use decimal arithmetic instead?
Use decimal arithmetic when the rules of the problem are expressed in decimal terms—for example, monetary calculations that require a prescribed number of decimal places and a defined rounding policy. Python’s decimal module supports decimal floating-point arithmetic and can represent decimal inputs such as 0.1 exactly within its model. Its context and rounding rules still matter; “decimal” does not remove the need to specify how results should be rounded. Python’s decimal documentation
Rank #2
Be careful about how you construct a decimal value. Converting an already-created float to Decimal preserves the float’s exact binary value, including its approximation; it does not recover the original decimal text. When the intended value is the decimal literal, construct from that text rather than from a float.
When is binary floating point appropriate?
Binary floating point is widely useful for scientific and engineering calculations, where values are often approximate and the computation’s error behavior matters more than exact decimal representation. Rather than assuming a computed approximation must equal an ideal real number exactly, define a comparison tolerance that fits the scale, accumulated error, algorithm, and decision at hand.
Python’s math.isclose can help express approximate equality, but no one tolerance is right for every magnitude or application. Blindly rounding inputs first does not fix the underlying representation issue: it changes the values being supplied to the operation, while those rounded decimal values still have to be represented in binary. Python’s tutorial discusses both approximate comparisons and pre-rounding.
How should you choose between decimal and binary arithmetic?
| Consideration | Decimal arithmetic | Binary floating point |
|---|---|---|
| Best fit | Rules defined in decimal terms, such as prescribed monetary rounding. | Approximate numerical work, including many scientific and engineering calculations. |
| Representation | Can represent decimal fractions such as 0.1 exactly within its model. | Finite precision; many decimal fractions have no finite binary representation. |
| How to manage results | Set an explicit scale, decimal context, and rounding policy. | Account for representation and operation rounding; use error analysis and problem-appropriate tolerances. |
| Implementation constraints | Check the language, runtime, libraries, and data interchange requirements. Performance depends on the specific implementation and workload; no universal speed comparison follows from the representation alone. | |
Further reading on IEEE 754
For a deeper technical treatment, SIAM lists Michael L. Overton’s Numerical Computing with IEEE Floating Point Arithmetic, second edition, published in 2025. The book covers IEEE 754, representation, correctly rounded arithmetic, exceptions, conditioning, and stability. SIAM’s book page.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →




