TExcelTAD
Home › Basic Math & Pre-Algebra › Units and Conversion

Units and Conversion

A measurement is a number and a unit: 5 is meaningless, 5 km is not. This lesson converts between units with conversion factors, chains several conversions, handles squared units and temperatures, and builds a small table-driven unit converter of the kind used in real software.

Conversion factors are fractions equal to 1

Since 1 km=1000 m1\ \text{km} = 1000\ \text{m}, the fraction 1000 m1 km\frac{1000\ \text{m}}{1\ \text{km}} equals 1. Multiplying by 1 does not change a quantity, only its unit. Choose the factor so the unit you want to get rid of cancels:

3.2 km×1000 m1 km=3200 mkm cancels4500 g×1 kg1000 g=4.5 kgg cancels\begin{aligned} 3.2\ \text{km} \times \frac{1000\ \text{m}}{1\ \text{km}} &= 3200\ \text{m} && \text{km cancels} \\ 4500\ \text{g} \times \frac{1\ \text{kg}}{1000\ \text{g}} &= 4.5\ \text{kg} && \text{g cancels} \end{aligned}

This method is called dimensional analysis (or the factor-label method). Writing the units out makes mistakes visible: if the units don't cancel, the factor is upside down.

Common conversions

Quantity Conversion
length 1 km=1000 m1\ \text{km} = 1000\ \text{m}, 1 m=100 cm1\ \text{m} = 100\ \text{cm}, 1 inch=2.54 cm1\ \text{inch} = 2.54\ \text{cm} (exact), 1 mile=1.609344 km1\ \text{mile} = 1.609344\ \text{km} (exact)
mass 1 kg=1000 g1\ \text{kg} = 1000\ \text{g}, 1 lb=0.45359237 kg1\ \text{lb} = 0.45359237\ \text{kg} (exact)
volume 1 L=1000 mL1\ \text{L} = 1000\ \text{mL}, 1 mL=1 cm31\ \text{mL} = 1\ \text{cm}^3
time 1 min=60 s1\ \text{min} = 60\ \text{s}, 1 h=3600 s1\ \text{h} = 3600\ \text{s}, 1 day=86 400 s1\ \text{day} = 86\,400\ \text{s}
data 1 kB=1000 B1\ \text{kB} = 1000\ \text{B}, 1 KiB=1024 B1\ \text{KiB} = 1024\ \text{B}, 1 byte=8 bits1\ \text{byte} = 8\ \text{bits}

Chaining conversions

Convert 90 km/h to metres per second:

90 km/h×1000 m1 km×1 h3600 s=90 000/3600 m/s=25 m/s90\ \text{km/h} \times \frac{1000\ \text{m}}{1\ \text{km}} \times \frac{1\ \text{h}}{3600\ \text{s}} = 90\,000 / 3600\ \text{m/s} = 25\ \text{m/s}

Each factor cancels one unit. And how many seconds are in a (non-leap) year? 365×24×60×60=31 536 000 s365 \times 24 \times 60 \times 60 = 31\,536\,000\ \text{s}.

Squared and cubed units

A square metre is 1 m×1 m=100 cm×100 cm1\ \text{m} \times 1\ \text{m} = 100\ \text{cm} \times 100\ \text{cm}, so 1 m2=10 000 cm21\ \text{m}^2 = 10\,000\ \text{cm}^2, not 100. Apply the factor once per dimension:

2.5 m2×(100 cm1 m)2=2.5×10 000 cm2=25 000 cm21 m3=1003 cm3=1 000 000 cm3=1000 L\begin{aligned} 2.5\ \text{m}^2 \times \left(\frac{100\ \text{cm}}{1\ \text{m}}\right)^2 &= 2.5 \times 10\,000\ \text{cm}^2 = 25\,000\ \text{cm}^2 \\ 1\ \text{m}^3 &= 100^3\ \text{cm}^3 = 1\,000\,000\ \text{cm}^3 = 1000\ \text{L} \end{aligned}

Temperature is different

Celsius and Fahrenheit have different zero points, so you cannot just multiply:

∘F=∘C×95+32∘C=(∘F−32)×59{}^\circ\text{F} = {}^\circ\text{C} \times \frac{9}{5} + 32 \qquad {}^\circ\text{C} = ({}^\circ\text{F} - 32) \times \frac{5}{9}

100 ∘C=212 ∘F100\ {}^\circ\text{C} = 212\ {}^\circ\text{F}, 0 ∘C=32 ∘F0\ {}^\circ\text{C} = 32\ {}^\circ\text{F}, and −40 is the same in both scales. Kelvin is Celsius shifted: K=∘C+273.15\text{K} = {}^\circ\text{C} + 273.15.

A table-driven converter

Real code stores factors to one base unit per quantity, then converts any unit to any other via the base. Decimal keeps the exact factors exact:

python · try it yourself
from decimal import Decimal as D

TO_METRES = {"mm": D("0.001"), "cm": D("0.01"), "m": D(1), "km": D(1000),
             "in": D("0.0254"), "ft": D("0.3048"), "mi": D("1609.344")}

def convert(value, unit_from, unit_to):
    metres = D(value) * TO_METRES[unit_from]
    return metres / TO_METRES[unit_to]

print(convert("3.2", "km", "m"))
print(convert("12", "in", "cm"))
print(convert("26.2", "mi", "km"))     # a marathon
print(convert("6", "ft", "m"))
print(convert("1", "km", "mi"))
3200.0
30.48
42.1648128
1.8288
0.6213711922373339696174341844

1 km → miles has no finite decimal (1000/1609.3441000/1609.344 is not a fraction with only 2s and 5s in the denominator), so Decimal gives 28 significant digits; round it for display.

Currency

Exchange rates are conversion factors that change every minute, and the "unit" is a currency. Converting money must round to the target currency's smallest unit, and some currencies have no cents at all:

python · try it yourself
from decimal import Decimal, ROUND_HALF_EVEN

RATES_PER_USD = {"USD": Decimal("1"), "EUR": Decimal("0.9210"), "JPY": Decimal("151.37")}
MINOR = {"USD": Decimal("0.01"), "EUR": Decimal("0.01"), "JPY": Decimal("1")}

def fx(amount, src, dst):
    usd = Decimal(amount) / RATES_PER_USD[src]
    return (usd * RATES_PER_USD[dst]).quantize(MINOR[dst], rounding=ROUND_HALF_EVEN)

print(fx("250.00", "USD", "EUR"))
print(fx("250.00", "USD", "JPY"))
print(fx("100.00", "EUR", "JPY"))
230.25
37842
16435

(The rates here are made up for the example.)

In software

  • Unit bugs are expensive. A famous spacecraft was lost because one team's software used pound-force seconds and another's used newton seconds. Store values in one base unit (SI) internally and convert only at the edges (input and display).
  • Units in names: timeout_ms, size_bytes, distance_m. Some languages and libraries (F# units of measure, Python's pint) check units at compile or run time.
  • Data sizes: disks are sold in GB (10910^9 bytes) but operating systems often show GiB (2302^{30} bytes), which is why a "1 TB" drive shows about 931 GiB. See Powers of Two.
  • CSS: 1 in=96 px=2.54 cm1\ \text{in} = 96\ \text{px} = 2.54\ \text{cm} by definition, and rem converts via the root font size.

Exercises

Exercise 1: One factor

Convert 7.5 kg to grams and 2400 mL to litres.

Answer

7500 g and 2.4 L

Solution
7.5 kg×1000 g1 kg=7500 g2400 mL×1 L1000 mL=2.4 L\begin{aligned} 7.5\ \text{kg} \times \frac{1000\ \text{g}}{1\ \text{kg}} &= 7500\ \text{g} \\ 2400\ \text{mL} \times \frac{1\ \text{L}}{1000\ \text{mL}} &= 2.4\ \text{L} \end{aligned}

Exercise 2: Chain them

A runner keeps a pace of 5 minutes per kilometre. What is that speed in km/h and in m/s?

Answer

12 km/h, which is 3133\frac{1}{3} m/s (about 3.33 m/s).

Solution
1 km5 min×60 min1 h=12 km/h12 km/h×1000 m1 km×1 h3600 s=12 000/3600=103≈3.33 m/s\begin{aligned} \frac{1\ \text{km}}{5\ \text{min}} \times \frac{60\ \text{min}}{1\ \text{h}} &= 12\ \text{km/h} \\ 12\ \text{km/h} \times \frac{1000\ \text{m}}{1\ \text{km}} \times \frac{1\ \text{h}}{3600\ \text{s}} &= 12\,000 / 3600 = \frac{10}{3} \approx 3.33\ \text{m/s} \end{aligned}

Exercise 3: Area and temperature

Convert 3 m23\ \text{m}^2 to cm2\text{cm}^2, and 25 °C to °F.

Answer

30 000 cm230\,000\ \text{cm}^2 and 77 °F

Solution
3 m2×(100 cm1 m)2=3×10 000=30 000 cm225×95+32=45+32=77 ∘F\begin{aligned} 3\ \text{m}^2 \times \left(\frac{100\ \text{cm}}{1\ \text{m}}\right)^2 &= 3 \times 10\,000 = 30\,000\ \text{cm}^2 \\ 25 \times \frac{9}{5} + 32 &= 45 + 32 = 77\ {}^\circ\text{F} \end{aligned}

Exercise 4: The missing gibibytes

A drive is sold as 2 TB (2×10122 \times 10^{12} bytes). Write Python that shows its size in GiB (2302^{30} bytes) and TiB (2402^{40} bytes), rounded to 1 decimal place.

Answer

About 1862.6 GiB, or 1.8 TiB.

Solution

2×1012/230=2 000 000 000 000/1 073 741 824≈1862.62 \times 10^{12} / 2^{30} = 2\,000\,000\,000\,000 / 1\,073\,741\,824 \approx 1862.6.

python · try it yourself
size = 2 * 10**12
print(f"{size / 2**30:.1f} GiB, {size / 2**40:.1f} TiB")
1862.6 GiB, 1.8 TiB

Test yourself

How many cm2\text{cm}^2 are in 1 m21\ \text{m}^2?

  1. 100
  2. 1000
  3. 10 000
  4. 1 000 000

To convert 54 km/h to m/s, multiply by…

  1. 10003600\frac{1000}{3600}
  2. 36001000\frac{3600}{1000}
  3. 60
  4. 160\frac{1}{60}

What is 50 °F in °C?

  1. 10 °C
  2. 18 °C
  3. 122 °C
  4. −10 °C