How UnitUtils Converts

This page records how every UnitUtils converter works: where each conversion factor comes from, what input is accepted, and how results are rounded and shown. It is written from the conversion code, which is covered by automated tests. For explanations of the units themselves, see the guides.

Unit definitions

  • Every unit is stored once, as its size in the base unit of its category (metres for length, kilograms for mass, litres for volume, watts for power and so on). A conversion is value × size of the source unit ÷ size of the target unit. No converter, table or page has its own copy of a factor.
  • Factors are the exact legal or SI definitions wherever one exists. The 1959 international yard and pound agreement fixes 1 yard at 0.9144 m and 1 pound at 0.45359237 kg, and the inch, foot, mile, ounce and stone follow from those.
  • The US gallon is 231 cubic inches, exactly 3.785411784 litres. The imperial gallon is exactly 4.54609 litres. US and imperial pints, quarts and fluid ounces are separate units; see US customary and imperial units.
  • The nautical mile is 1,852 m, so a knot is 1,852 m per hour. A standard atmosphere is 101,325 Pa and a bar 100,000 Pa.
  • The calorie is the thermochemical calorie, 4.184 J, and the BTU is the International Table BTU, 1,055.05585262 J.
  • Horsepower (hp) is mechanical horsepower, 550 foot-pounds per second, 745.6998715822702 W. Metric horsepower (PS) is a separate unit, 75 kgf·m/s with standard gravity, exactly 735.49875 W; see horsepower and power.
  • The pound-force uses standard gravity, 9.80665 m/s², and psi is pound-force per square inch. The millimetre of mercury is the conventional value of 133.322387415 Pa.
  • Data uses decimal prefixes (1 kB = 1,000 bytes) and binary prefixes (1 KiB = 1,024 bytes) as separate units; see metric prefixes, bits and bytes.
  • An average month and an average year use the Gregorian mean year of 365.2425 days. A day is exactly 24 hours.

Temperature

  • Temperature scales have different zero points, so they are converted with a formula rather than a single factor: °F = °C × 9 ÷ 5 + 32, °C = (°F − 32) × 5 ÷ 9 and K = °C + 273.15.
  • These formulas convert readings. A temperature difference converts by the factor alone: a change of 10 °C is a change of 18 °F. See Celsius, Fahrenheit and Kelvin.
  • A temperature below absolute zero (−273.15 °C, −459.67 °F, 0 K) is rejected.

Precision and rounding

  • Results are calculated in double-precision arithmetic and tidied to 12 significant digits, which removes floating-point artefacts.
  • By default a result is shown to 6 significant digits, so 75 kg is shown as 165.347 lb. A whole-number part is never shortened: 1,234,567.891 is shown as 1,234,568, not 1,235,000. The converter can also show a fixed number of decimal places.
  • Values of 1,000,000,000,000,000 or more, and values smaller than 0.000000001, are shown in exponent form, such as 1.5e+18, so no digits are invented.
  • Tables of common conversions use the same converter and the same 6-significant-digit rounding as the result above them.
  • Numbers are written with a dot for decimals and commas for thousands, whatever the language of your browser.

Stones and pounds, feet and inches

  • Where a result is also shown as whole units and a remainder (stones and pounds, feet and inches), the whole units are counted first and the remainder is rounded to one decimal place.
  • If the rounded remainder reaches a whole unit, it is carried, so a result is never shown as 11 st 14.0 lb or 5 ft 12.0 in. 70 kg is shown as 11 st 0.3 lb and 1.8 m as 5 ft 10.9 in.
  • A decimal number of stones is a fraction of a stone: 11.5 st is 11 st 7 lb. See stones and pounds.

Accepted input

  • A number may have a sign, a decimal point and an exponent (1e-3). Commas are accepted only as thousands separators in the right places, so 1,000 is one thousand and 1,5 is rejected rather than guessed to mean one and a half.
  • Negative values are rejected for quantities that cannot be negative: mass, volume, area, time, data and frequency. They are accepted for length, speed, temperature, pressure, energy, power, force and angle, where a negative value can describe a direction or a change.
  • Values larger than 10 to the power 30 are rejected.

What the converters do not do

  • They do not convert between mass and volume (for example grams of flour to cups), which needs the density of the ingredient.
  • They do not correct for conditions: an airspeed in knots converts to the same airspeed in mph, and a gauge pressure stays a gauge pressure.

If a result looks wrong, please get in touch.