Unit conversion looks like the most solved problem in arithmetic. It is also the cause of one of the most expensive software failures on record (the Mars Climate Orbiter, lost because one system produced pound-force seconds and another consumed newton-seconds) and of a steady stream of smaller errors in recipes, invoices and engineering spreadsheets.
The reason is that "convert units" covers several different operations.
Ratio scales: a single factor
Length, mass, duration, energy and data have a true zero. Zero metres is no length, and two metres is twice one metre. Conversion is one multiplication and the ratios compose:
1 inch = 25.4 mm (exact, by definition)
1 mile = 1,609.344 m (exact)
1 kg = 2.20462262 lb
The first two are exact because the inch and the yard were redefined in terms of the metre in 1959. That is worth knowing: many imperial units are now defined metrically, so the conversion is not an approximation.
Interval scales: a factor and an offset
Celsius and Fahrenheit have arbitrary zeros. Zero degrees is not the absence of temperature, so ratios are meaningless: 20 °C is not twice as hot as 10 °C in any physical sense.
°F = °C × 9/5 + 32
°C = (°F − 32) × 5/9
The offset also means differences convert differently from values. A rise of 10 °C is a rise of 18 °F, not 50 °F. Applying the value formula to a difference is a standard bug in weather and process-control code.
Kelvin is the exception: it has a true zero, so it is a ratio scale and 200 K really is twice 100 K.
The same name, different sizes
Several unit names mean different quantities depending on where you are:
- Gallon. US 3.785 L, imperial 4.546 L: about 20% apart.
- Fluid ounce. US 29.57 mL, imperial 28.41 mL.
- Ton. Short 907 kg, long 1,016 kg, metric 1,000 kg.
- Pint. US 473 mL, imperial 568 mL.
- Billion. Now 10⁹ almost everywhere, but older European documents use 10¹².
None of these is signalled by the unit name, so a fuel-economy or shipping-weight figure copied between two documents can be 10–20% wrong with nothing to flag it. A unit converter that names the system explicitly (US liquid gallon, not "gallon") is not being pedantic; it is the only way the answer is defined.
Conversions that need a property
Some "conversions" are not unit conversions:
Mass to volume requires density. 1 kg of water is 1 L; 1 kg of flour is about 1.9 L; 1 kg of honey is about 0.7 L. This is why cup measurements in recipes are unreliable across ingredients, and why professional baking uses mass.
Currency requires a rate, which changes every second and differs between mid-market, card and cash. There is no intrinsic factor between two currencies; a currency converter reports a rate at a moment, not a fact.
Data rate to transfer time requires the actual throughput, not the advertised one. And bits versus bytes is a factor of eight that connection speeds and file sizes deliberately state differently.
KB versus KiB. 1 kB is 1,000 bytes; 1 KiB is 1,024. Storage manufacturers use the first, operating systems historically used the second, and the gap grows with scale: about 7% at the gigabyte level and 10% at the terabyte level, which is exactly why a "2 TB" drive shows as 1.81 TB.
Practical rules
- Write the unit next to every number, in cells, variables and API fields.
- Name the system, not just the unit:
us_gallons, notgallons. - Convert at the boundary, store one canonical unit internally.
- Treat temperature differences separately from temperature values.
- Round at the end, once.
Check figures with the unit converter, which names the system for every ambiguous unit, and carry any chain of conversions at full precision, rounding once at the end.