Why Does 0.1 + 0.2 = 0.30000000000000004?
Quick answer: In ordinary arithmetic, 0.1 + 0.2 = 0.3 exactly. But computers usually use IEEE 754 binary floating-point numbers, which cannot represent 0.1, 0.2 or 0.3 exactly, just as 1/3 cannot be written exactly in decimal. They store the nearest available values instead. Adding the stored 0.1 and 0.2 gives a result that must be rounded again, and it lands on the floating-point number just above the stored 0.3, whose shortest decimal form is 0.30000000000000004. This is normal rounding, not a calculation bug.
Facts checked November 22, 2026.
Type 0.1 + 0.2 into JavaScript or Python and you get 0.30000000000000004, and 0.1 + 0.2 == 0.3 is false. It looks like a bug, and it has fooled programmers for decades, but the computer is following exact mathematical rules. The cause is something you already know from school: some fractions never end when written in a given base.
Step 1: Some Fractions Never End
In base 10, \(\frac{1}{3} = 0.3333\ldots\) never ends, because 3 does not divide any power of 10. A fraction terminates in base 10 only if its denominator (in lowest terms) has no prime factors other than 2 and 5. In base 2, a fraction terminates only if its denominator is a power of 2. Since
\[ 0.1 = \frac{1}{10} = \frac{1}{2 \times 5}, \]the factor 5 means 0.1 has no finite binary form:
\[ 0.1_{10} = 0.0\overline{0011}_2 = 0.000110011001100110011\ldots_2 \]The pattern 0011 repeats forever. The same is true of 0.2 and 0.3, while numbers like 0.5 (\(\frac{1}{2}\)) and 0.25 (\(\frac{1}{4}\)) are exact. Review comparing decimals if needed.
Step 2: Rounding to 53 Binary Digits
The standard 64-bit “double” format (IEEE 754 binary64) stores 1 sign bit, 11 exponent bits and 52 fraction bits, giving 53 significant binary digits for normal numbers, like scientific notation in base 2. Anything longer is rounded to the nearest representable value. The actual stored values are:
| You type | Exact value actually stored |
|---|---|
| 0.1 | 0.1000000000000000055511151231257827021181583404541015625 |
| 0.2 | 0.200000000000000011102230246251565404236316680908203125 |
| 0.3 | 0.299999999999999988897769753748434595763683319091796875 |
| 0.1 + 0.2 | 0.3000000000000000444089209850062616169452667236328125 |
The stored 0.1 and 0.2 are both slightly too big. Their sum is rounded again, to the representable number just above 0.3, while the stored 0.3 is just below 0.3. They are neighboring floating-point numbers, not the same one, so 0.1 + 0.2 == 0.3 is false. When printed with the fewest digits that identify it uniquely, the sum shows as 0.30000000000000004.
Why the Last Digit Is 4: A Rounding Tie
Add the two stored values exactly and you get 0.3000000000000000166533453693773481063544750213623046875. That exact sum is not itself a double. It lies exactly halfway between two neighboring doubles: the stored 0.3 (about 0.29999999999999998890) and the next double up (about 0.30000000000000004441). Each is about \(2.78 \times 10^{-17}\) away. IEEE 754’s default rule, round to nearest, ties to even, picks the neighbor whose last binary digit is 0. In hexadecimal, the stored 0.3 is 0x1.3333333333333p-2 and the sum is 0x1.3333333333334p-2: the tie went to the “even” ending 4, which is the upper neighbor.
How Big Is the Error?
The gap between 1 and the next double is \(2^{-52} \approx 2.22 \times 10^{-16}\), called machine epsilon. Doubles are accurate to about 15 to 16 significant decimal digits. The error in \(0.1 + 0.2\) is about \(4.4 \times 10^{-17}\): tiny, but enough to break an exact equality test.
How to Compare Decimals Safely
Try it yourself in Python:
print(0.1 + 0.2) # 0.30000000000000004
print(0.1 + 0.2 == 0.3) # False
import math
print(math.isclose(0.1 + 0.2, 0.3)) # True
from decimal import Decimal
print(Decimal("0.1") + Decimal("0.2")) # 0.3
print(Decimal(0.1)) # exact stored value of 0.1
- Use a tolerance: instead of
a == b, check whether \(|a – b|\) is small, for example with Python’smath.isclose(0.1 + 0.2, 0.3), which returnsTrue. Choose relative and absolute tolerances to suit the size of your numbers and the accuracy you need. - Use decimal types for money: Python’s
Decimal("0.1") + Decimal("0.2")gives exactly0.3, and databases offer DECIMAL types that store base-10 digits exactly. - Round for display, not in the middle of calculations: rounding intermediate results can make errors worse.
- Use integers: store 10 cents as the integer 10, not 0.10 dollars.
- Use fractions: Python’s
fractions.Fraction(1, 10) + Fraction(2, 10)gives exactly 3/10.
When Tiny Errors Became Big Problems
In 1991, during the Gulf War, a Patriot missile battery in Dhahran, Saudi Arabia, failed to intercept an incoming Scud missile; 28 US soldiers were killed. A US General Accounting Office report traced the failure to timing: the system counted time in tenths of a second and converted it using the value 1/10 truncated to fit a 24-bit fixed-point register (a different format from today’s 64-bit doubles). The conversion factor was off by about \(9.5 \times 10^{-8}\), so the computed time drifted by that fraction of every tenth-of-a-second count. After about 100 hours, or 3,600,000 tenths of a second, the drift reached roughly 0.34 seconds, enough for the tracking window to miss a fast-moving missile:
\[ 9.5 \times 10^{-8} \times 3{,}600{,}000 \approx 0.34 \text{ s}. \]Floating Point and AI
Modern AI deliberately uses lower precision: 16-bit formats such as bfloat16, and even 8-bit or 4-bit numbers, because neural networks tolerate small rounding errors and fewer bits mean faster, cheaper matrix multiplication. Engineers keep critical sums in higher precision to stop errors from accumulating. Rounding is also why the same AI model can give very slightly different numbers on different hardware.
Common Misconceptions
“This is a JavaScript bug.” No. Every language using IEEE 754 doubles, including Python, Java and C, gives the same result.
“Computers can’t do math.” They do exact binary math on rounded inputs. The rounding happens when decimals are converted to binary.
“Using more decimal places fixes it.” Printing more digits only reveals the stored value; it does not make 0.1 exact in binary.
Watch: Floating Point Explained
If you learn better by watching, these videos are worth your time.
Check Your Understanding
Five quick questions to see how much of this has stuck. Pick an answer and press Submit; you will see a short explanation either way.
Answer each question and press Submit to see your result right away.
Frequently Asked Questions
Why does 0.1 + 0.2 not equal 0.3?
Because 0.1, 0.2 and 0.3 cannot be represented exactly in binary floating point. Each is rounded to the nearest double, and the rounded sum of 0.1 and 0.2 is a slightly different double than the rounded 0.3.
Why does 0.1 + 0.2 equal 0.30000000000000004?
The exact stored sum is 0.3000000000000000444…, which is printed with the fewest digits needed to identify it: 0.30000000000000004.
How do you compare floating point numbers?
Check whether their difference is smaller than a small tolerance, for example with Python’s math.isclose, instead of testing exact equality.
Does JavaScript and Python give the same answer for 0.1 + 0.2?
Yes. Both use IEEE 754 64-bit doubles and print 0.30000000000000004; some languages or display settings simply show fewer digits.
Is floating point error a bug?
No. It is a documented property of the IEEE 754 standard used by almost all computers and languages.
How should programs handle money?
Use integers (such as cents) or decimal types that store base-10 digits exactly, rather than binary floating point.
Keep Exploring
- Why AI Runs on Matrix Multiplication (and Why GPUs Matter)
- Information Theory Explained: Entropy, Bits and AI
- How to Check ChatGPT Math: 7 Ways to Verify Answers
Sources and Further Reading
Related to This Article
More math articles
- How to Identify Graphs of Basic Functions
- NES Elementary Education Math (103) Worksheets: FREE & Printable
- Equal Protection Clause
- FREE 3rd Grade MCAS Math Practice Test
- The Best Grade 3 Math Book for Texas Students
- Utopian Communities and Changing Family Ideals: Beliefs, Rules and Power
- The Best Algebra 2 Book for Students Who Want It to Click
- The Ultimate AFOQT Math Formula Cheat Sheet
- Full-Length 6th Grade GMAS Math Practice Test
- Market supply adds quantities at each price


What people say about "Why Does 0.1 + 0.2 = 0.30000000000000004? - Effortless Math"?
No one replied yet.