Methodology
How we define units, store conversion constants, handle temperature and special cases, and format results.
Unit definitions and base units
Every unit belongs to a measurement category. Within each category, one unit is designated the base unit. All other units in the category express their relationship to the base unit through a single conversion factor.
Category base units:
- Length → meter (m)
- Area → square meter (m²)
- Volume → liter (L)
- Weight / Mass → kilogram (kg)
- Temperature → Celsius (°C)
- Speed → meter per second (m/s)
- Pressure → pascal (Pa)
- Energy → joule (J)
- Power → watt (W)
- Data → bit (bit)
- Force → newton (N)
- Torque → newton-meter (N·m)
Base units were chosen based on SI standards where applicable, and practical convention elsewhere (liters over cubic meters for volume, for example).
Multiplicative conversions
Most conversions are multiplicative. Each unit stores a single factor_to_base constant. Conversion from unit A to unit B uses a two-step approach:
Step 1 — Convert A to the base unit: base_value = input × A.factor_to_base
Step 2 — Convert the base unit to B: result = base_value ÷ B.factor_to_base
This avoids storing N² conversion factors between all pairs. Only N factors are needed (one per unit relative to the base).
All factors are stored as exact IEEE 754 double-precision values using the best available constant. Where an exact rational exists (e.g., 1 inch = exactly 25.4 mm), the exact value is used. Where an authoritative source provides a rounded constant (e.g., 1 BTU = 1055.05585262 J per ISO 31-4), that value is used.
Affine conversions (temperature)
Temperature scales use affine (linear with offset) conversions, not purely multiplicative ones. The Celsius scale is used as the base.
Each temperature unit stores two values:
- factor_to_base: the scale factor
- offset_to_base: the additive offset applied after scaling, going TO Celsius
Conversion from Fahrenheit to Celsius (to base): base = (°F × 5/9) + (−160/9) which simplifies to: °C = (°F − 32) × 5/9
Conversion from Celsius to Fahrenheit (from base): °F = (°C − offset) / factor = (°C − (−160/9)) / (5/9) = (°C × 9/5) + 32
Kelvin: To Celsius: °C = K − 273.15 From Celsius: K = °C + 273.15
The engine handles both directions using the stored factor and offset, ensuring a single formula path works correctly for all temperature conversions.
Ambiguous and context-dependent units
Several unit names are ambiguous depending on regional convention or context. UnitFormula handles these explicitly rather than silently assuming one interpretation.
Key ambiguities and how they are handled:
Gallon — two different gallons exist: • US liquid gallon = 3.785411784 liters • Imperial gallon (UK) = 4.54609 liters Both are stored as distinct units with clear labels. Pages and tools specify which gallon is in use. Ambiguity warnings are shown on relevant pages.
Tonne / ton — three different "tons": • Metric tonne = 1,000 kg • US short ton = 907.18474 kg • Imperial long ton = 1,016.0469088 kg All three are stored and labeled explicitly. "Ton" alone is never silently resolved.
Pound (lb vs lbf) — mass vs force: • Pound-mass (lb) = 0.45359237 kg (mass unit) • Pound-force (lbf) = 4.44822 N (force unit, defined as the gravitational force on 1 lb mass at standard gravity) These are in separate categories (weight/mass vs force) and are never conflated.
Data units — decimal vs binary prefixes: • Decimal: 1 KB = 1,000 bytes (IEC 80000-13, used for storage marketing) • Binary: 1 KiB = 1,024 bytes (IEC 80000-13, used for RAM, filesystems) Both systems are available and labeled clearly. Pages note when OS or hardware context affects the expected prefix.
Pressure — gauge vs absolute: • Gauge pressure (psig) is measured relative to ambient atmospheric pressure. • Absolute pressure (psia) includes the ~14.696 psi of atmospheric pressure. This tool converts between pressure units, not between gauge and absolute reference frames. Contextual notes are shown where relevant.
Result formatting and precision
Raw conversion results are IEEE 754 double-precision floats. Before display, results are formatted as follows:
Default precision: 6 significant decimal places (configurable per tool).
Trailing zeros are stripped. The result 1.500000 is shown as 1.5.
Very large values (≥ 10¹²) or very small non-zero values (< 10⁻⁶) are shown in scientific notation.
Quick reference tables on pair pages use the same precision setting as the page default.
No banker's rounding or special rounding modes are applied. Standard JavaScript toFixed() with trailing-zero stripping is used for display formatting.
Note: floating-point arithmetic means that some results may differ from exact rational values in the last few digits. For example, 1 mile / 1609.344 m/mile in double-precision may produce 0.000621371192... rather than exactly 0.000621371. This is an inherent property of binary floating-point, not an error in our constants.
Sources and references
Conversion factors and unit definitions are drawn from:
- NIST Special Publication 811 (2008 Edition), "Guide for the Use of the International System of Units (SI)" — primary source for SI-related constants.
- NIST Special Publication 1038, "The International System of Units (SI)" — supplementary SI reference.
- ISO 31 and IEC 80000 series — for derived and specialty units.
- BIPM (International Bureau of Weights and Measures) — authoritative definitions for kilogram, meter, second, kelvin, and ampere.
- US National Bureau of Standards (now NIST) — for US customary unit exact definitions (1 inch = 25.4 mm, 1 pound = 0.45359237 kg).
Where a factor is exactly defined (e.g., 1 inch = 25.4 mm exactly), the exact value is stored. Where a factor is a measured or derived approximation, the best available published value is used and noted.