LEARN AT YOUR PACE

Why 0.1 + 0.2 is not 0.3 on a computer

Published

If you type 0.1 + 0.2 in JavaScript or Python, the result is 0.30000000000000004, not 0.3. It happens on every computer, because computers store decimals as fractions whose denominator is 2, 4, 8, 16… and 0.1 cannot be written that way. The fraction sum 1/10 + 2/10 does give 3/10 and loses nothing.

Worked example: the same sum with fractions

Add 0.1 and 0.2 without binary numbers.

  1. Write each decimal as a fraction. 0.1 = 1/10 and 0.2 = 2/10.
  2. Add the numerators. The denominators are already equal: 1 + 2 = 3.
  3. Keep the denominator. The result cannot be simplified.

Result: 0.3, with no error.

Check: 3/10 is three tenths, and 0.1 + 0.2 is also three tenths.

To turn any decimal into a fraction, use the decimal to fraction calculator, which starts from the digits you typed.

What the computer actually stores

Programming languages almost always use double-precision floating-point numbers (IEEE 754). Each one is a fraction whose denominator is a power of 2. When you write 0.1, the program stores the closest one: 3602879701896397/2⁵⁵, which equals 0.1000000000000000055511151231257827… That is slightly more than 0.1. The Python documentation states that what is stored for 0.1 is the binary fraction 3602879701896397 / 2**55, close to 1/10 but not equal to it.

The screen rounds when it displays a number, so 0.1 looks correct. Ask for more digits and the difference appears.

What is stored compared with the decimal value you type
You typeStoredDifference from what you typed
0.10.1000000000000000055511…+5.6 × 10⁻¹⁸
0.20.2000000000000000111022…+1.1 × 10⁻¹⁷
0.30.2999999999999999888977…−1.1 × 10⁻¹⁷
Stored sum of 0.1 + 0.20.3000000000000000444089…+4.4 × 10⁻¹⁷ relative to 0.3

The stored 0.2 is exactly twice the stored 0.1, so it carries twice the error. When the two are added, the result is rounded again to the nearest binary fraction, and that number differs from the one stored for 0.3. The two land on opposite sides of 3/10, which is why the comparison 0.1 + 0.2 == 0.3 is false. The computer’s addition is done correctly; the starting numbers are what changed.

Why 1/10 does not fit in binary

A fraction in lowest terms has a finite expansion in a base when its denominator uses only the prime factors of that base. In base 10 those are 2 and 5. In base 2, only 2. The denominator 10 includes a 5, so in binary it repeats forever: 0.000110011…₂, with the block 0011. It is the same effect that makes 1/3 equal 0.333… in base 10, with a different prime and a different base. The guide to terminating decimal fractions develops the rule in base 10, and the one on exact and repeating decimals explains how a repeating block is written.

To tell the two cases apart, look at the denominator after simplifying.

Decimals the computer stores without error and decimals it does not
DecimalFractionExact in binary?
0.51/2Yes, denominator 2
0.1251/8Yes, denominator 8 = 2³
0.6255/8Yes, 0.101₂
0.21/5No, the denominator 5 is not a power of 2
0.33/10No, the denominator 10 includes a 5
0.753/4Yes, denominator 4

Among the tenths, only 0.5 is stored without error; quarters and eighths are exact too. To see the decimal for any fraction and find out whether it terminates or repeats, use the fraction to decimal calculator.

What to do in practice

There are three ways out, depending on what you need.

For amounts of money, another option is to count in cents with whole numbers and divide by 100 only when displaying. Integers up to 2⁵³ are stored without loss, so every sum comes out exact. The right choice depends on the system.

The calculator on this site follows the same principle: it works with integers and fractions, so 0.1 + 0.2 gives 3/10 in the fraction calculator. The decimal you see is a presentation of the result, and the fraction is the reference value. The methodology explains how calculations are done and checked.

Source: Python documentation, Floating-Point Arithmetic: Issues and Limitations (accessed October 16, 2026). The values in the table were checked with exact fraction arithmetic.

Next step

Fraction blog Pick a fraction article by what you need: prepare a lesson, practice, understand a procedure, or read a curiosity, with one example of each.
Report an errorHow we handle corrections

Use the fraction calculator

YOUR CALCULATOR, CLOSE AT HAND

Save your calculator

Open your browser menu and choose “Install app” or “Add to Home Screen”. You can also bookmark this page.