Technology & Computing · Software & algorithms

Why a computer can't write down one tenth

Trace 0.1 into binary and back, and see why adding it three times doesn't give 0.3, why rounding first doesn't help, and what to do instead.

4 short lessons · about 20 minutes · 5 sources · updated November 2026

What you will learn

  • Explain why most decimal fractions can't be stored exactly in binary
  • Say what a machine actually stores when a program is given the value 0.1
  • Predict the result of an equality test between an accumulated float and a literal
  • Choose a comparison that works with approximate values

Lesson 1 of 4 · 5 min

Why a computer can't store 0.1 exactly

Before you readIn 1991 a Patriot missile battery missed an incoming Scud because its computer stored one tenth slightly wrong. After running more than 100 hours, how far off was its clock?

Correct.Not quite. The answer is About a third of a second.

Its clock was off by about a third of a second, enough for a Scud to move more than half a kilometer. This lesson shows why a computer can't store one tenth exactly.

On February 25, 1991, a Patriot missile battery in Dhahran, Saudi Arabia, failed to track an incoming Scud missile. The Scud hit an Army barracks and killed 28 Americans. Investigators traced the failure to the way the battery's computer handled one small number, one tenth.

Computers store fractions in binary, which works like decimal with a different base. The decimal 0.625 means 6 tenths, 2 hundredths and 5 thousandths. The binary 0.101 means one half, no quarters and one eighth. Those are the same number written two ways.

Most decimals aren't that lucky. You know the problem from one third. In decimal you can write 0.3, then 0.33, then 0.333, and you never get there. Whether a fraction ends depends on the base.

Binary can only finish a fraction built from halves, quarters, eighths and so on. One tenth isn't. In binary it's 0.0 followed by 0011 again and again, forever. A computer has a fixed number of binary digits, called bits, so it has to stop somewhere.

Check yourselfWhy can a computer store 0.5 exactly in binary but not 0.1?

Correct.Not quite. The answer is One half is a binary place value, but one tenth repeats forever in binary.

Binary place values are halves, quarters, eighths and so on. One half is one of them, so 0.5 is stored exactly. One tenth can't be built from a finite number of them, so it repeats forever and has to be cut off. The count of decimal digits doesn't matter, and 0.1 is nowhere near too small to store.

What the computer keeps is the nearest binary fraction it can hold. Numbers stored this way are called floating-point numbers, or floats. On nearly every machine today, a float keeps the first 53 bits. For one tenth, the stored value is exactly 0.1000000000000000055511151231257827021181583404541015625.

That's a little more than one tenth. You get the same value on nearly every phone and laptop, because they share one standard format.

You rarely see it, because programs round what they display. Python prints the shortest decimal that leads back to the same stored value, and for this value that's 0.1. So you type 0.1, the machine stores the long number, and the screen shows 0.1 again.

None of this is a bug in the program or the language. It happens in every language that uses the computer's built-in arithmetic, because the limit is in binary itself.

Try to recallA program is given the literal 0.1 and later prints it as 0.1. What's actually stored, and why doesn't the display show it?

What's stored is the nearest binary fraction the computer can hold. One tenth repeats forever in binary and only the first 53 bits are kept, so the stored value is slightly more than one tenth. The screen still shows 0.1 because programs round what they display. Python prints the shortest decimal that leads back to the same stored value, and that's 0.1.

Back to Dhahran. The Patriot's clock counted time in tenths of a second. To turn the count into seconds, the computer multiplied it by its stored one tenth, which had been cut off after 24 bits.

Each tenth came up short by about a ten-millionth of a second. The battery had been running for more than 100 hours, and by then its clock was off by about a third of a second. A Scud covers more than half a kilometer in that time, so the system looked in the wrong place.

Today's computers keep 53 bits where the Patriot kept 24, so their one tenth is far closer. It still isn't one tenth.

Lessons in this topic

  1. Why a computer can't store 0.1 exactly

    One tenth repeats forever in binary, so a computer stores a near miss. See what it stores, why you rarely notice, and what happened when a missile battery relied on it.

    Essentials · 5 min

  2. Why 0.1 + 0.1 + 0.1 isn't 0.3 on a computer

    Three slightly wrong tenths add up to a slightly wrong total, and an exact comparison notices. See why rounding first doesn't help and what to compare with.

    Essentials · 5 min

  3. Inside a 64-bit number, and where counting breaks

    A double splits its 64 bits into a sign, an exponent and a mantissa. The mantissa's size sets the point, near 9 quadrillion, where whole numbers stop being exact.

    Deeper · 5 min

  4. Why floats suit measurements but not money

    Floats are right for measured quantities and wrong when the decimal digits themselves must be exact, as with money. See the exact alternatives and how to look at what a float really holds.

    Deeper · 5 min

Three quick stories from this topic

Three tenths that aren't

A computer adds 0.1 three times and gets 0.30000000000000004, which it says isn't 0.3

Each 0.1 is stored as a binary fraction a hair above one tenth, so the three small errors add up. The stored 0.3 is a different near miss. Rounding the inputs first doesn't help, because they're already as close as the format allows.

Rounding first doesn't help

Round each value to one decimal place and the comparison is still False. The values are already as close to their decimals as the format allows.

Test for closeness instead

Python's math.isclose reports that sum and 0.3 as close. For adding many values, sum uses extended precision, and math.fsum rounds only once.

The Patriot's one tenth

A Patriot missile battery failed in 1991 because its computer couldn't store one tenth

Its clock counted tenths of a second, and one tenth repeats forever in binary, so the stored value was cut short. After more than 100 hours of running, the error had grown to about a third of a second. The Scud it missed killed 28 American soldiers.

Why one tenth won't fit

In binary, one tenth is 0.000110011 with 0011 repeating forever, the way one third is 0.333 forever in decimal. Any computer has to cut it off somewhere.

A third of a second

A Scud covers more than half a kilometer in that time, so the battery looked in the wrong place. Corrected software arrived in Dhahran the next day.

Where counting by ones stops

In JavaScript, 9,007,199,254,740,992 plus 1 equals 9,007,199,254,740,992

A JavaScript number keeps 53 binary digits of precision. Past 2 to the 53rd power, about 9 quadrillion, the values it can hold are 2 apart, so adding 1 lands back on the same number. X sends its post IDs as text for this reason.

Sixty-four bits, three jobs

One bit holds the sign, 11 hold the exponent and 52 hold the digits. A leading 1 that's never stored brings the precision to 53 bits.

Why big IDs travel as text

X's documentation shows the ID 10765432100123456789 coming out of JavaScript as 10765432100123458000. Sent as text, every digit survives.

Sources

This topic is part of Why computers don't do what you'd expect, a guided path through related topics.

  • Searching a million items

    See why a sorted list of a million items takes about 20 checks to search, when sorting first is worth the effort, and how a hash table skips the search altogether.

    4 lessons · 17 min

  • What an algorithm is

    An algorithm is a list of steps exact enough for a machine to follow. See how to write one, how to show it always finishes with the right answer, and why the word now covers looser things.

    4 lessons · 18 min

  • How programming works

    Most programs are built from a handful of ideas. See how variables, decisions, loops and functions fit together, and learn to read a short program line by line. No experience needed.

    4 lessons · 16 min

  • Why adding cores stops helping

    A fixed job has a part that won't split, and that part sets a ceiling no number of processors can lift.

    4 lessons · 24 min

  • How encryption works

    Encryption scrambles a message so only someone with the right key can read it. See how a shared key works, how strangers agree on one in public, and what end-to-end encryption in a chat app promises.

    4 lessons · 16 min

  • What artificial intelligence is

    AI is one label for many machines, from spam filters to chatbots. See what they share, how learned systems differ from hand-written rules, and how to test a claim about what AI can do.

    4 lessons · 16 min

All technology & computing topics · Take the quiz