Skip to content

rounding error

A rounding error is the difference between the exact result a calculation would produce with unlimited precision and the value left after rounding each number to fit a finite-precision format, such as a float.

The error has two sources:

  • Representation error appears because most real numbers have no exact finite form in a given base. For example, the decimal 0.1 becomes an infinitely repeating binary fraction, so the stored value is only the nearest representable approximation.
  • Arithmetic error appears when an operation’s true result must itself be rounded back into the format, even when both inputs were exact. For example, adding 1.0 to 2.0 ** 53 leaves the value unchanged, because the exact result lands between two representable floats and rounds back to 2.0 ** 53.

The relative error of a single rounding step is bounded by the format’s machine epsilon, the gap between 1 and the next representable value.

Rounding errors matter most when they compound. For example, over a long sequence of operations they can accumulate until they dominate the result. Subtracting two nearly equal numbers can also magnify them sharply, an effect called catastrophic cancellation.

Rounding error is distinct from truncation error, which comes from approximating a continuous process with finitely many steps, not from finite precision.

How to Round Numbers in Python

Tutorial

How to Round Numbers in Python

In this tutorial, you'll learn what kinds of mistakes you might make when rounding numbers and how you can best manage or avoid them. It's a great place to start for the early-intermediate Python developer interested in using Python for finance, data science, or scientific computing.

intermediate best-practices python

For additional information on related topics, take a look at the following resources:


By Martin Breuss • Updated June 22, 2026 • Reviewed by Leodanis Pozo Ramos