Skip to content
Back to all articles
floating pointroundingbill splitting

Why Does 0.1 + 0.2 Not Equal 0.3 (and How to Split a Bill Without Losing a Cent)

Short answer: computers store most decimals as binary approximations, so 0.1 + 0.2 comes out as 0.30000000000000004. Money should be handled in whole cents, which is also how to split a bill so the shares add up exactly.

6 min read

Short answer: most decimal fractions, such as 0.1, cannot be stored exactly in the binary format computers use, so tiny errors appear and 0.1 + 0.2 gives 0.30000000000000004 instead of 0.3. The fix is not to avoid computers. It is to round only at the end, compare numbers with a tolerance, and do money arithmetic in whole cents. Splitting a bill follows the same rule: divide the cents, not the dollars.

Why does 0.1 + 0.2 not equal 0.3?

Computers store ordinary numbers as binary fractions. A fraction like 1/3 cannot be written exactly in decimal (0.3333...), and in the same way 1/10 cannot be written exactly in binary. The stored value of 0.1 is a very close neighbour, not 0.1 itself.

We ran this in JavaScript, the language behind most web pages, and printed more digits than usual:

  • 0.1 is stored as 0.100000000000000005551
  • 0.1 + 0.2 returns 0.30000000000000004
  • 0.1 + 0.2 === 0.3 returns false
  • 0.7 + 0.1 returns 0.7999999999999999
  • 1.1 times 3 returns 3.3000000000000003

Nothing is broken. Any language that uses standard double-precision numbers behaves this way. The error is about 0.00000000000000004, which is invisible unless something checks for exact equality or rounds at the wrong moment.

When does this error actually matter?

Rarely in the displayed answer, often in the logic around it. Three situations cause real problems:

  1. Exact comparisons. A program that asks "is the total exactly 0.3?" gets the wrong answer.
  2. Rounding halves. A value that looks like a tie may sit just below it.
  3. Adding many rounded pieces. Each piece is rounded, and the rounded pieces no longer sum to the rounded total.

The second one is the surprising one. In JavaScript, (1.005).toFixed(2) returns "1.00", not "1.01". The reason is that 1.005 is stored as 1.00499999999999989342, which is below the halfway point, so rounding it down is correct for the number actually stored.

What is the right way to handle it?

  • Round once, at the end. Keep full precision through the calculation and round only the number you display.
  • Compare with a tolerance. Instead of a === b, check whether the absolute difference is smaller than a tiny threshold. We checked that the absolute value of 0.1 + 0.2 - 0.3 is less than 0.000000001, which is true.
  • Use whole units for money. Store 1,999 cents rather than 19.99 dollars. Integer arithmetic on cents is exact, as long as the numbers stay within a safe size.

A quick check on the last point: 10 cents plus 20 cents is 30 cents exactly, and dividing by 100 at the very end shows 0.3.

How do you split a bill so the shares add up?

Divide the total in cents, give every person the whole-cent share, and hand the leftover cents out one at a time. This guarantees that the shares add up to the bill. Dividing in dollars and rounding each share does not.

Worked example: three people split a 100.00 dinner with no tip.

  • Naive: 100 / 3 = 33.33 rounded, times 3 = 99.99. One cent has vanished.
  • Cents method: 10,000 cents / 3 = 3,333 each with 1 cent left over. The first person pays 33.34 and the other two pay 33.33. The shares add up to 100.00.

We ran Mathify's bill split calculator logic with these inputs and it returns 33.34, 33.33 and 33.33. Its code works in integer cents and gives leftover cents to the first people in the list, one cent each. That is a convention, not a law of arithmetic. If you would rather one person never pays the extra cent, rotate who goes first.

What happens with a tip, and with more people?

Rounding errors grow when there are more shares and more rounded steps. Three more cases, all computed:

  • 87.50 bill, 18% tip, 3 people. The total is 103.25. Rounding a third of it gives 34.42 each, and 3 times 34.42 is 103.26, one cent too much. The cents method gives 34.42, 34.42 and 34.41, which add up to 103.25.
  • 100.00 bill, 7 people. A rounded share is 14.29, and 7 times 14.29 is 100.03. The cents method gives four people 14.29 and three people 14.28, which add up to 100.00.
  • Naive rounding can go either way. In the first example above it ran one cent short, in the second and third it ran over.

For the tip itself, the tip calculator shows the tip and total for a single bill. The article on splitting restaurant bills covers tip etiquette and different splitting styles.

Common mistakes

  • Comparing two decimal results with an equals sign instead of a tolerance.
  • Rounding every line item and then summing the rounded numbers, when the total should be rounded once.
  • Rounding a share to the nearest cent and assuming the shares sum to the total.
  • Trusting an old spreadsheet column formatted to two decimals. Formatting changes what you see, not the stored value, so two cells that look equal can differ.
  • Using the "half rounds up" rule by eye on a value that is stored just below the half.

Key takeaways

  • 0.1 + 0.2 = 0.30000000000000004 in standard computer arithmetic. It is expected behaviour, not a bug.
  • Round at the end, compare with a tolerance, and keep money in whole cents.
  • Split bills by dividing cents and distributing the remainder so the shares add up to the total.
  • If two tools disagree by a cent, check where each one rounds.

For everyday sums, the percentage calculator and the basic calculator are quick ways to cross-check a number. This article is for general information about arithmetic, not financial advice.

FAQ

Is 0.1 + 0.2 = 0.30000000000000004 a bug in JavaScript?

No. It follows the IEEE 754 double-precision standard, which most programming languages use for ordinary decimal numbers, so the same sum gives the same result in any language that uses it.

How do I stop floating point errors in a spreadsheet?

Round the final result with a rounding function rather than only formatting the cell, and avoid testing two decimal results for exact equality. For money, many people keep a cents column of whole numbers.

Why do the shares on a split bill sometimes differ by one cent?

A bill that is not divisible by the number of people leaves a remainder of cents. Someone has to pay it, so the shares differ by one cent. That is a correct result, not an error.

Should the tip be calculated before or after tax?

Practices vary by place and by person, so there is no single rule to cite. Decide on the base before you calculate and use it for everyone. Mathify's bill split applies the tip percentage to the subtotal you enter.

Does Mathify round before or after adding things up?

For bill splits it converts the total to cents, allocates the cents across people and adds them back, so the shares always add up to the total. For other calculators, check the formula shown on the page.

Topics:#floating point#rounding#bill splitting#calculation mistakes

Related Articles

Ready to start calculating?

Use our free calculators to make data-driven decisions for your financial and health goals.

Explore Calculators