Skip to main content
ExplainerFloating-Point MathArchitecture Explainer· 4 min read· in Technology

Why 0.1 + 0.2 Does Not Equal 0.3 in Modern Programming

The IEEE 754 standard forces computers to approximate infinite real numbers within a finite 64-bit space, creating tiny rounding errors that compound in financial and scientific calculations.

By Sergei Orlov

Hardware Architects 40%Financial Software Developers 30%Scientific Computing Researchers 30%
Hardware Architects
Prioritize computational speed and silicon efficiency over base-10 exactness, arguing that approximations are necessary for performance.
Financial Software Developers
Reject floating-point arithmetic entirely for currency, relying on arbitrary-precision decimal libraries to prevent compounding ledger errors.
Scientific Computing Researchers
Rely on the massive dynamic range of floating-point numbers but actively manage error bounds to prevent catastrophic cancellation in simulations.

Perspectives this story doesn't cover

  • Compiler Designers
  • Machine Learning Engineers

The IEEE 754 committee dictates how modern silicon understands the physical universe. When hardware architects at Intel, AMD, or Apple design a new processor, they allocate exactly 64 bits of memory to represent any real number, from the mass of an electron to the distance between galaxies. They codify this trade-off in the IEEE 754 standard, which was most recently revised in 2019.[2]

This 64-bit constraint creates a fundamental mathematical boundary. There are infinitely many real numbers between 0.1 and 0.2, but a 64-bit register can only represent exactly 18,446,744,073,709,551,616 unique states. To fit infinity into finite silicon, the hardware must approximate almost every number it encounters, snapping it to the nearest available binary value.[1][3]

The problem surfaces immediately with basic decimal fractions. In base-10 mathematics, the fraction 1/10 is written cleanly as 0.1. But computers operate in base-2. In binary, 0.1 becomes a repeating fraction: 0.0001100110011, continuing forever in a pattern that cannot be perfectly resolved.

How 64 bits of memory are divided to represent a floating-point number.

Because the processor only has 53 bits allocated for the significand—the part of the floating-point number that holds the significant digits—it must eventually truncate this infinite sequence. The hardware rounds the repeating binary fraction at the 53rd bit, permanently altering the value before any math even takes place.[2][4]

"Floating-point arithmetic is considered an esoteric subject by many people," notes David Goldberg in his foundational 1991 ACM Computing Surveys paper, but the consequences of this truncation are highly visible. When a developer asks a program to store 0.1, the CPU actually stores 0.1000000000000000055511151231257827021181583404541015625.[1]

The same quantization error applies to 0.2, which is stored in memory as 0.200000000000000011102230246251565404236316680908203125. When the arithmetic logic unit adds these two approximations together, it perfectly executes the math on the imperfect inputs.

The sum of those two stored values is exactly 0.3000000000000000444089209850062616169452667236328125. When the programming language formats this result back into base-10 for the user's screen, it rounds it to the nearest displayable decimal, yielding the infamous 0.30000000000000004.[6]

The sum of those two stored values is exactly 0.3000000000000000444089209850062616169452667236328125.

This is not a bug in Python, JavaScript, or C++. It is the intended behavior of the IEEE 754 standard, originally drafted in 1985 under the leadership of Turing Award winner William Kahan. The committee deliberately chose computational speed and massive dynamic range over base-10 exactness.[1][4]

By standardizing this format, hardware manufacturers could build dedicated Floating-Point Units directly into the silicon. This allows modern processors to execute billions of these approximations per second, enabling real-time 3D rendering, video encoding, and complex physics simulations without stalling the CPU.

Hardware floating-point units execute operations exponentially faster than software-based decimal libraries.

However, this speed trade-off becomes catastrophic in financial software. A banking application that uses floating-point numbers to calculate a 5 percent interest rate on a $10,000 balance will eventually compound these microscopic rounding errors into missing cents, violating strict accounting ledgers.[5]

"You can use floating-point numbers for money," argues software engineer Evan Jones, provided the developer strictly bounds the values to integers under 2^53 (exactly 9,007,199,254,740,992) to avoid fractional quantization entirely. But most financial institutions mandate arbitrary-precision decimal libraries instead, trading raw processor speed for mathematical certainty.[5]

In scientific computing, the stakes are different. Researchers running fluid dynamics or climate models rely on floating-point math for its massive dynamic range. A 64-bit float can represent values as small as 2.22 × 10^-308 and as large as 1.79 × 10^308, allowing a single simulation to track both microscopic particles and planetary masses.

The danger in these simulations is "catastrophic cancellation." If a physics model subtracts two nearly equal floating-point numbers, the significant digits cancel out, leaving only the quantization error. This error then propagates through subsequent calculations, potentially invalidating the entire simulation.[1]

To mitigate this, data scientists rely on the concept of machine epsilon—the upper bound on the relative approximation error. For double-precision floats, machine epsilon is 2^-52, or roughly 2.22 × 10^-16. Algorithms must be explicitly designed to keep cumulative errors well above this threshold.[3][6]

Because 0.1 cannot be perfectly represented in base-2, the hardware truncates the repeating fraction.

As the computing industry shifts toward artificial intelligence, the IEEE 754 standard is adapting again. Machine learning models do not require 53 bits of precision; they require massive throughput. This has driven the adoption of smaller 16-bit and 8-bit floating-point formats, trading exactness for the ability to pack more parameters into GPU memory.[2]

The 0.1 plus 0.2 quirk remains a permanent fixture of computer science. It serves as a mandatory lesson for every new programmer: the machine does not understand human mathematics, it only understands the finite silicon boundaries it was engineered to respect.[7]

Key points

  • Modern processors use the IEEE 754 standard to represent real numbers in exactly 64 bits of memory.
  • Because computers calculate in binary, simple decimal fractions like 0.1 become repeating fractions that must be truncated.
  • The sum of 0.1 and 0.2 yields 0.30000000000000004 because the hardware is perfectly adding two imperfect approximations.
  • Financial applications avoid this by using arbitrary-precision decimal libraries, while scientific models rely on floats for their massive dynamic range.

Key terms

Floating-point
A method of representing real numbers in computing that supports a wide range of values by trading exactness for dynamic range.
Significand
The part of a floating-point number that contains its significant digits, determining the precision of the value.
Machine epsilon
The upper bound on the relative error caused by rounding in floating-point arithmetic; the smallest difference the machine can distinguish.
Catastrophic cancellation
A severe loss of precision that occurs when two nearly equal floating-point numbers are subtracted, leaving only their rounding errors.

Frequently asked

Why does 0.1 + 0.2 equal 0.30000000000000004?

Because computers operate in base-2 (binary), where 0.1 and 0.2 are repeating fractions. The hardware truncates these fractions to fit into 64 bits of memory, and adding those two truncated approximations together yields a number slightly larger than 0.3.

Is this a bug in my programming language?

No. Almost all modern languages, including Python, JavaScript, and C++, use the IEEE 754 standard for floating-point math. The language is correctly returning the exact result of the hardware's approximation.

How do I calculate money accurately in code?

Never use floating-point numbers for currency. Instead, use your language's built-in decimal library (like Python's 'decimal' module) or store money as integers representing the smallest unit, such as cents.

Sources

Source coverage

7 outlets

3 viewpoints surfaced

Hardware Architects 40%Financial Software Developers 30%Scientific Computing Researchers 30%
  1. [1]OracleScientific Computing Researchers

    What Every Computer Scientist Should Know About Floating-Point Arithmetic

    Read on Oracle
  2. [2]IEEE SAHardware Architects

    IEEE 754-2019 - IEEE Standard for Floating-Point Arithmetic

    Read on IEEE SA
  3. [3]Wolfram MathWorld

    Floating-Point Representation

    Read on Wolfram MathWorld
  4. [4]GeeksforGeeks

    IEEE Standard 754 Floating Point Numbers

    Read on GeeksforGeeks
  5. [5]evanjones.caFinancial Software Developers

    You can use floating-point numbers for money!

    Read on evanjones.ca
  6. [6]University of MarylandHardware Architects

    The IEEE 754 Format

    Read on University of Maryland
  7. [7]Factlen Editorial Team

    Synthesis by Factlen editorial team

    Read on Factlen Editorial Team

Comments

Stay informed

Every angle. Every day.

Get Technology stories with full source coverage and perspective breakdowns delivered to your inbox.