The Mathematics of Unit Conversion: Precision, Rounding & Standards

In September 1999, NASA's Mars Climate Orbiter arrived at the red planet and promptly disintegrated in its atmosphere. The cause was embarrassingly terrestrial: one engineering team worked in pound-force seconds, another in newton-seconds, and nobody converted. A $125-million spacecraft was destroyed by a unit mismatch. Unit conversion looks like primary-school arithmetic — until precision, standards and software artefacts enter the picture. This guide is the missing manual.

Standards first: which factors are exact?

The modern metric system (SI) is not a suggestion; it is defined by international agreement, and since the 2019 redefinition every base unit traces to fixed constants of nature. Crucially, many conversion factors are exact by definition, not measurements:

  • 1 inch = 25.4 millimetres, exactly — fixed by the 1959 international yard-and-pound agreement.
  • 1 kilometre = 1000 metres — SI prefixes are decimal powers, always exact.
  • 1 kilogram = 1000 grams — trivially exact, unlike the pre-2019 kilogram, which was a platinum-iridium cylinder in a Paris vault.
  • 1 nautical mile = 1852 metres, exactly — adopted by international convention.

Others are genuinely approximate: 1 mile ≈ 1.609344 km is exact (it follows from the inch definition), but 1 kg ≈ 2.20462 lb is a rounded convenience — the exact ratio is a non-terminating decimal. A trustworthy converter knows which is which and documents it.

Why 0.1 + 0.2 ≠ 0.3: floating point in the wild

Computers store most decimal numbers in IEEE 754 double-precision binary floats: 1 sign bit, 11 exponent bits, 52 mantissa bits. The mantissa can only represent fractions whose denominator is a power of two — and one tenth is not. 0.1 is stored as the nearest binary fraction, a hair above or below the true value.

0.1 + 0.2          // 0.30000000000000004
(1/3) * 3          // 1.0000000000000002
0.1 + 0.2 === 0.3  // false

Alone, each error is minuscule (about one part in 10¹⁶). The danger is accumulation through conversion chains: convert metres → feet → inches → kilometres → miles and back, and round-trip identity no longer holds — you get 499.99999999999983 where you entered 500. Well-engineered converters fight this with guard digits, rational arithmetic where factors are exact, and single-rounding discipline.

Rounding: the silent design decision

Every displayed result is rounded; how matters more than most developers realise:

  • Round-half-up (5 always inflates) is what school taught and what users expect.
  • Round-half-to-even (“banker's rounding”, the IEEE 754 default) biases neither upward nor downward across large datasets — which is why finance and science prefer it.
  • Significant figures ≠ decimal places. Reporting 26.4 miles as “26.40” claims precision the input never had. Honest converters track input precision or let you choose significant digits.
  • Round once, at the end. Rounding at every intermediate step compounds error; keep full precision internally and format only for display.
Pharmacy-grade rule: if a rounding decision could hurt someone — dosages, fuel loads, structural loads — the display must also state the precision convention used. Ambiguity is a defect.

Temperature is a different beast entirely

Length, mass and volume conversions are proportional: multiply by a factor and you're done. Temperature scales are affine — they have an offset and a scale factor:

°F = °C × 9/5 + 32
K  = °C + 273.15

Forgetting the 32-degree offset is the classic beginner bug. A robust implementation converts through an absolute scale (kelvin or rankine) as the canonical pivot: it makes the algebra symmetric, eliminates sign errors around zero, and generalises cleanly to Rankine and Réaumur.

Designing a converter you can actually trust

The failure modes above translate directly into an engineering checklist — the same one convert.clicktools.app is being built against:

  1. One canonical unit graph. Convert every unit to and from its SI base via declared factors. Never maintain an N×N table of pairwise factors — it drifts and duplicates errors.
  2. Exact factors as exact rationals. 25.4 mm per inch is precisely 127/5; storing it as a rational removes a whole class of binary artefacts.
  3. Round-trip tests. For every unit pair, convert(convert(x)) must return x to within tolerance — ideally exactly.
  4. Reference values from standards documents. Pin tests to NIST/BSI published tables, not to another website's output.
  5. Precision in, honesty out. Preserve input significant figures and round once, transparently, at display time.

The takeaway

Correct conversion is a chain of small, disciplined decisions: exact factors where standards define them, full precision through every intermediate step, one deliberate rounding at the end, and tests that pin the whole pipeline to published references. Mars Climate Orbiter was lost in the gap between “looks right” and “is right” — a gap a careful converter closes by construction. And because all of this is deterministic arithmetic on a few bytes, it runs flawlessly in your browser tab, with no server ever seeing your numbers.

Next in the series: the cryptography that proves a document hasn't changed by a single byte.

Digital signatures →