Computer Science

Floating-Point Arithmetic: Why Computers Make Rounding Errors

Published: January 08, 2026 • Updated: January 08, 2026 • 9 min read • By Calculator Archive Editorial Team

Anyone who has opened a browser console and typed 0.1 + 0.2 has seen the infamous result: 0.30000000000000004. Far from being a software bug, this is a direct consequence of how hardware implements binary floating-point numbers under the IEEE-754 standard — the same standard used by JavaScript, Python, Java, and essentially every programming language.

The Binary Fraction Problem

Just as 1/3 cannot be written finitely in base-10 (it becomes 0.3333...), fractions whose denominators contain prime factors other than 2 cannot be written finitely in base-2. In binary, the decimal value 0.1 becomes an infinite repeating sequence:

0.110 = 0.00011001100110011...2

The computer must truncate this sequence at a fixed bit boundary, introducing a rounding error of roughly 10-17 before the calculation even starts. Add 0.2 (which has its own tiny error), and the sum lands just above 0.3 — printing as 0.30000000000000004.

The IEEE-754 Double-Precision Format

In standard 64-bit floating point, every number is packed into three bitfields:

The implied leading 1 means only the fraction is stored, and the 53rd significand bit position is where rounding decisions occur. Two numbers that are distinct in decimal can map to the same 64-bit pattern — for example, any dollar amount above $253 (~$9 quadrillion) can no longer be represented exactly, which is why financial systems track money in integer cents rather than floating-point dollars.

Where the Errors Come From

Three operations introduce error, and they compound:

  1. Representation error — the decimal input is not exactly representable in binary (the 0.1 problem).
  2. Cancellation error — subtracting nearly equal numbers discards significant digits (e.g., computing small differences in large coordinates).
  3. Accumulation error — summing millions of values in a loop drifts unless the order is controlled.
The classic test: 0.1 + 0.2 === 0.3 evaluates to false in JavaScript, while Math.abs((0.1 + 0.2) - 0.3) < Number.EPSILON evaluates to true. Never compare floats for exact equality — compare their difference against a tolerance.

How Calculators Compensate

Production calculators avoid displaying raw binary artifacts using three techniques:

Calculator Archive applies epsilon comparisons plus decimal normalization so results render as clean mathematical values — 0.3 shows as 0.3, and currency rows total exactly to the cent.

Test the Scientific Calculator Engine

Run trigonometric, logarithmic, and high-precision calculations and see clean results without floating-point artifacts.

Frequently Asked Questions

Why does 0.1 + 0.2 not equal 0.3 in programming?
Decimal 0.1 and 0.2 have infinite repeating expansions in binary, so the computer stores slightly rounded values. Their sum lands just above 0.3, which prints as 0.30000000000000004.
Is this a bug in JavaScript or my computer?
Neither. It is the IEEE-754 floating-point standard that all modern CPUs and languages use. The same result appears in Python, Java, C, and Excel.
How should I compare floating-point numbers?
Compare the absolute difference against a small tolerance (an epsilon) rather than using strict equality. For money, use integer cents or a decimal library instead of binary floats.
How many decimal digits can a double safely store?
A 64-bit double holds about 15 to 17 significant decimal digits. Beyond that, digits are rounding noise rather than meaningful precision.