Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

units

numbers with units, combined and converted; live currency rates

Example results generated on 2026-10-08. Ones using now, today or randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.

types

# quantity
5 km

operators

# qty ± qty
1 km + 300 m
# → 1.3 km
# qty * / qty
100 km / 2 h
# → 50 km/h
# qty ** int
(3 m) ** 2
# → 9 m^2
# qty < qty
1 mi > 1 km
# → true

pretty

# long: best prefix, thousands separators
pretty(12345678 m)
# → "12,345.7 km"
# short: best prefix, K M B T
pretty(12345678 m, "short")
# → "12.3K km"
# durations split into d h min s, money keeps its own display: see time, money

conversions

# to unit
5 km to mi
# → 3.10686 mi
# in unit
5 km in mi
# → 3.10686 mi
# to unit unit
1.8 m to ft in
# → "5 ft 10.8661 in"
# to compound
100 km / 2 h to mph
# → 31.0686 mph

your own units

# unit sprint = 2 wk        then  3 sprint to d → 42 d
# unit pizza                a new base unit, for counting
# unit slice = pizza / 8    then  3 slice to pizza → 0.375 pizza

Units

kindnames
lengthm, meter, meters, metre, metres; km, kilometer, kilometers; cm, centimeter, centimeters; mm, millimeter, millimeters; µm, um, μm, micrometer, micrometers, micron; nm, nanometer, nanometers; mi, mile, miles; yd, yard, yards; ft, foot, feet; in, inch, inches; px, pixel, pixels; nmi; au; ly, lightyear, lightyears
masskg, kilogram, kilograms; g, gram, grams; mg, milligram, milligrams; µg, ug, μg, microgram, micrograms; t, tonne, tonnes; lb, lbs, pound, pounds; oz, ounce, ounces; st, stone
times, sec, secs, second, seconds; ms, millisecond, milliseconds; µs, us, μs, microsecond, microseconds; ns, nanosecond, nanoseconds; min, mins, minute, minutes; h, hr, hrs, hour, hours; d, day, days; wk, week, weeks; mo, month, months; yr, year, years; workday, workdays; workwk, workweek, workweeks; workmo, workmonth, workmonths; workyr, workyear, workyears
temperatureK, kelvin; C, celsius, degC; F, fahrenheit, degF
volumeL, l, liter, liters, litre, litres; mL, ml, milliliter, milliliters; gal, gallon, gallons; qt, quart, quarts; pt, pint, pints; cup, cups; floz; tbsp, tablespoon, tablespoons; tsp, teaspoon, teaspoons
areaha, hectare, hectares; acre, acres
speedkph, kmh; mph; kn, knot, knots
databit, bits; B, byte, bytes; KB; MB; GB; TB; PB; KiB; MiB; GiB; TiB; PiB; kbit, Kb; Mbit, Mb; Gbit, Gb
ratebps; kbps; Mbps; Gbps
energyJ, joule, joules; kJ; MJ; cal, calorie, calories; kcal, Cal; Wh; kWh; eV; BTU, btu
powerW, watt, watts; kW; MW; hp, horsepower
pressurePa, pascal; kPa; MPa; bar; atm; psi; mmHg
forceN, newton, newtons; kN; lbf
anglerad, radian, radians; deg, degree, degrees; turn, turns
currentA, amp, amps, ampere, amperes; mA, milliamp, milliamps; µA, uA, μA; kA
voltageV, volt, volts; mV; µV, uV, μV; kV
resistanceΩ, ohm, ohms; mΩ, mohm; kΩ, kohm; MΩ, Mohm
chargecoulomb, coulombs; mAh; Ah
capacitancefarad, farads; mF; µF, uF, μF; nF; pF
conductanceS, siemens; mS
magnetic_fluxWb, weber, webers; mWb
magnetic_fieldT, tesla, teslas; mT; µT, uT, μT
inductanceH, henry, henries; mH; µH, uH, μH
frequencyHz, hertz; kHz; MHz; GHz; rpm
amountmol, mole, moles; mmol; µmol, umol, μmol; kmol
concentrationM, molar; mM, millimolar; µM, uM, μM, micromolar
lightlm, lumen, lumens; cd, candela, candelas
illuminancelx, lux; fc, footcandle, footcandles
doseSv, sievert, sieverts; mSv, millisievert, millisieverts; µSv, uSv, μSv, microsievert, microsieverts

Submodules

moduleabout
constantsphysical constants (CODATA 2018); Planck’s constant is h_planck
moneycurrencies, live exchange rates, paid time like workday and workyr
goofybananas for scale, smoots, fortnights; every item also works as item_for_scale
kitchencups to grams with ingredient densities

Functions

functiondescription
simplify(q: quantity)the quantity in the prefixed unit of the same family that reads best, like 1.2 m or 3.6 kW; also to best
all_units()every unit as a table: {name, full, desc, aliases, kind, si, source}; source is units, goofy, currency or user
db(ratio: num, kind?: str)a power ratio in decibels (10 log10); kind “amplitude” for voltage or pressure ratios (20 log10)
from_db(db: num, kind?: str)decibels back to a power ratio, or an amplitude ratio with “amplitude”

simplify

simplify(q: quantity): the quantity in the prefixed unit of the same family that reads best, like 1.2 m or 3.6 kW; also to best

0.0012 km to best
# → 1.2 m
3600 J/s to best
# → 3.6 kW
1 kg*m^2/s^2 to best
# → 1 J
1.5e9 B.simplify
# → 1.5 GB

all_units

all_units(): every unit as a table: {name, full, desc, aliases, kind, si, source}; source is units, goofy, currency or user

all_units().len
# → 266
all_units().filter(|u| u.kind == "length").map(|u| u.name).take(5)
# → ["m", "km", "cm", "mm", "µm"]
all_units().filter(|u| u.source == "goofy")[0]
# → {name: "banana", full: "banana", desc: "a typical banana, 17.8 cm; the internet's favorite scale", aliases: ["bananas"], kind: "length", si: 0.178 m, source: "goofy"}

See also: simplify

db

db(ratio: num, kind?: str): a power ratio in decibels (10 log10); kind “amplitude” for voltage or pressure ratios (20 log10)

db(2)
# → 3.0103
db(1000)
# → 30
db(2, "amplitude")
# → 6.0206

See also: from_db, log

from_db

from_db(db: num, kind?: str): decibels back to a power ratio, or an amplitude ratio with “amplitude”

from_db(3)
# → 1.99526
from_db(-6, "amplitude")
# → 0.501187

See also: db

More examples

units

# speed from distance and time
100 km / 2 h to mph
# → 31.0686 mph
# feet and inches
1.8 m to ft in
# → "5 ft 10.8661 in"
# mixed units add
5 ft 11 in to cm
# → 180.34 cm
# drive time
300 mi / 65 mph to h min
# → "4 h 36.9231 min"
# download time
4 GB / 100 Mbps to min
# → 5.33333 min
# why a 1 TB disk shows less
1 TB to GiB
# → 931.323 GiB
# area
3 m * 4 m to ft^2
# → 129.167 ft^2
# running pace
1 h / 10 km to min/mi
# → 9.65606 min/mi
# force
9.81 m/s^2 * 70 kg to N
# → 686.7 N
# a month of a 60 W bulb
60 W * 8 h * 30 to kWh
# → 14.4 kWh
# temperature
101 F to C
# → 38.3333 C
# a 1080p screen at 96 dpi
1080 px to in
# → 11.25 in
# twice the power
db(2)
# → 3.0103
# +3 dB louder means
from_db(3)
# → 1.99526
# 20 USD to EUR   (currencies use live rates)