All posts

Why some calculators say 0.1 + 0.2 = 0.30000000000000004

A short, friendly look at how computers store decimals, and how we keep the noise off your screen.

If you have ever typed 0.1 + 0.2 into a programming console, you may have seen 0.30000000000000004. It looks like a bug. It isn’t one, but it is a good reason to be careful with decimals.

Computers count in twos

We write numbers in base ten, so a tenth is tidy: 0.1. Computers store numbers in base two. In binary, one tenth can’t be written exactly, in the same way one third becomes 0.3333… in decimal and never ends.

The computer keeps as many binary digits as it has room for and rounds the rest. The stored “0.1” is a hair more than one tenth, and so is the stored “0.2”. Add them together and the tiny excess shows up in the 17th decimal place.

Does it matter?

For everyday sums, no. The error is about four parts in a hundred million billion. It only becomes visible because the computer prints every digit it has.

It does matter if a calculator shows those digits to you. A bill that reads $12.300000000000001 is confusing even if it is, for practical purposes, $12.30.

What we do about it

stepbystepcalculator.com rounds every result to 12 significant digits before showing it. That is far more precision than a shopping list, a recipe or a tax estimate needs, and it is enough to hide the binary noise. So 0.1 + 0.2 shows 0.3, and 1 ÷ 3 shows 0.333333333333.

The same rounded number is what goes into your step history, so if you restore a step and keep going, you carry on from exactly what you saw.

When you need more than this

Accounting software and banking systems often avoid the problem by counting whole cents instead of fractions of a dollar. If you are doing work where every cent is audited, use a tool designed for that job and check the figures it produces.

Sources