units
numbers with units like km, kg or mph: calculate with them and convert between them
Permissions: network
Numbers with units, like 5 km or 60 km/h. Units carry through arithmetic, so a distance divided by a time is a speed, and to converts to another unit.
writing
Section titled “writing”Units combine with *, / and ^, like m/s^2. Most take the metric prefixes: k for kilo, M for mega, m for milli, µ or u for micro, and so on.
good to know
Section titled “good to know”Adding or comparing quantities of different kinds, like meters and seconds, is an error rather than a meaningless number.
Tags: conversion
simplifythe quantity in the prefix of its unit that reads best, like 3.6 kW instead of 3600 Wsithe quantity in standard metric (SI) unitskindthe kind of quantity, like length or force, or its SI units when the kind has no nameall_unitsevery unit zil knows, as a tablerefresh_ratesfetch the latest currency exchange rates now, and return how many currencies they coverdba ratio of two powers in decibels, as 10 × log10(ratio), so doubling is about +3 dBfrom_dbdecibels back to the ratio of powers, the reverse of db
1# quantity: a number with a unit25 km3# a unit power: m^2, m2 or m²45 m² to cm250000 cm^2syntax
Section titled “syntax”1# + and - convert to a common unit21 km + 300 m1.3 km3# * and / combine the units4100 km / 2 h50 km/h5# ** raises the unit too6(3 m) ** 29 m^27# < and > compare across units81 mi > 1 kmtrue9# to a unit105 km to mi3.10686 mi11# in works the same as to125 km in mi3.10686 mi13# to several units splits it across them141.8 m to ft in"5 ft 10.8661 in"15# to a combined unit16100 km / 2 h to mph31.0686 mph17# unit sprint = 2 wk defines a unit from others, then 3 sprint to d gives 42 d18# unit pizza on its own makes a new unit for counting things, unrelated to the rest19# unit slice = pizza / 8 builds on it, then 3 slice to pizza gives 0.375 pizzapretty
Section titled “pretty”1# long, the default: best prefix, separators2pretty(12345678 m)"12,345.7 km"3# short: K, M, B and T for thousands up to trillions4pretty(12345678 m, "short")"12.3K km"5# durations and money have their own styles, shown in help("time") and help("money")| kind | units |
|---|---|
| length | m, meter, meters, metre, metres; km, kilometer, kilometers; cm, centimeter, centimeters; mm, millimeter, millimeters; µm, um, μm, micrometer, micrometers, micron; nm, nanometer, nanometers; px, pixel, pixels; Å, angstrom, angstroms; RU, rack_unit, rack_units; point, points; pica, picas; twip, twips; tex_pt; didot, didots; cicero, ciceros; agate, agates; mi, mile, miles; yd, yard, yards; ft, foot, feet; in, inch, inches; nmi; thou, mil, mils; fathom, fathoms; chain, chains; rod, rods, perch, perches, pole, poles; span, spans; barleycorn, barleycorns; link, links; ft_us; au; ly, lightyear, lightyears; pc, parsec, parsecs; light_second, light_seconds; light_minute, light_minutes; light_hour, light_hours |
| mass | kg, kilogram, kilograms; g, gram, grams; mg, milligram, milligrams; µg, ug, μg, microgram, micrograms; t, tonne, tonnes; ct, carat, carats; Da, dalton, daltons, amu; lb, lbs, pound, pounds; oz, ounce, ounces; st, stone; gr, grain, grains; dr, dram, drams; ozt; lbt; scruple, scruples; dwt, pennyweight, pennyweights; long_ton, long_tons; short_ton, short_tons; cwt, hundredweight, hundredweights; earth_mass, earth_masses; jupiter_mass, jupiter_masses; solar_mass, solar_masses |
| time | s, 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; decade, decades; century, centuries; millennium, millennia; workday, workdays; workwk, workweek, workweeks; workmo, workmonth, workmonths; workyr, workyear, workyears; schoolyr, schoolyear, schoolyears; yr_julian; yr_tropical |
| temperature | K, kelvin; C, celsius, degC; delta_K, delta_kelvin; delta_C, delta_degC; delta_F, delta_degF; F, fahrenheit, degF; Ra, rankine |
| volume | L, l, liter, liters, litre, litres; mL, ml, milliliter, milliliters; cc; dsp, dessertspoon, dessertspoons; cup_metric; gal_uk; qt_uk; pt_uk; gill_uk; floz_uk; gal, gallon, gallons; qt, quart, quarts; pt, pint, pints; cup, cups; floz; tbsp, tablespoon, tablespoons; tsp, teaspoon, teaspoons; gill, gills; fldr; minim, minims; butt, butts; tun, tuns; bu, bushel, bushels; pk, peck, pecks; dry_qt; dry_pt |
| area | ha, hectare, hectares; are, ares; darcy, darcys; L_100km, lp100km; acre, acres; rood, roods; cmil; kcmil, MCM; section, sections; township, townships |
| speed | kph, kmh; mph; kn, knot, knots |
| data | bit, bits, shannon, shannons; nat, nats; trit, trits; dit, hartley, hartleys; octet, octets; word; B, byte, bytes; KB; MB; GB; TB; PB; KiB; MiB; GiB; TiB; PiB; kbit, Kb; Mbit, Mb; Gbit, Gb |
| rate | bps; kbps; Mbps; Gbps |
| energy | J, joule, joules; kJ; MJ; cal, calorie, calories; kcal, Cal; Wh; kWh; eV; cal_it; Ha, hartree, hartrees; BTU, btu; thm, therm, therms; erg, ergs; foe, foes |
| power | W, watt, watts; kW; MW; PS; hp, horsepower; TR, ton_refrigeration; solar_luminosity |
| pressure | Pa, pascal; kPa; MPa; bar; atm; mmHg; hPa; mbar; Torr, torr; mmH2O; psi; inHg; inH2O; ksi; barye, baryes |
| force | N, newton, newtons; kN; gf; kgf, kilopond; lbf; ozf; pdl, poundal, poundals; dyn, dyne, dynes |
| angle | rad, radian, radians; deg, degree, degrees; turn, turns, rev, revs, revolution, revolutions, cycle, cycles; arcmin, arcminute, arcminutes; arcsec, arcsecond, arcseconds; grad, gon, gons, gradian, gradians |
| current | A, amp, amps, ampere, amperes; mA, milliamp, milliamps; µA, uA, μA; kA; abA, abampere, abamperes, biot, biots |
| voltage | V, volt, volts; mV; µV, uV, μV; kV; statV, statvolt, statvolts; abV, abvolt, abvolts |
| resistance | Ω, ohm, ohms; mΩ, mohm; kΩ, kohm; MΩ, Mohm; statohm, statohms; abohm, abohms |
| charge | coulomb, coulombs; mAh; Ah; statC, statcoulomb, statcoulombs, franklin, franklins |
| capacitance | farad, farads; mF; µF, uF, μF; nF; pF |
| conductance | S, siemens; mS |
| magnetic_flux | Wb, weber, webers; mWb; Mx, maxwell, maxwells |
| magnetic_field | T, tesla, teslas; mT; µT, uT, μT; Gs, gauss |
| inductance | H, henry, henries; mH; µH, uH, μH; abH, abhenry, abhenries |
| frequency | Hz, hertz; kHz; MHz; GHz; rpm; Bq, becquerel, becquerels; Ci, curie, curies; Rd, rutherford, rutherfords |
| amount | mol, mole, moles; mmol; µmol, umol, μmol; kmol; einstein, einsteins |
| concentration | M, molar; mM, millimolar; µM, uM, μM, micromolar |
| light | lm, lumen, lumens; cd, candela, candelas |
| illuminance | lx, lux; nit, nits, nt; fc, footcandle, footcandles; fL, foot_lambert, foot_lamberts; phot, phots; sb, stilb, stilbs; lambert, lamberts |
| dose | Sv, sievert, sieverts; mSv, millisievert, millisieverts; µSv, uSv, μSv, microsievert, microsieverts; Gy, gray, grays; rad_dose; rem |
| viscosity | poise; cP, centipoise |
| kinematic_viscosity | St, stokes; cSt, centistokes |
| flow | sverdrup, sverdrups; cfm; cfs; gpm; gph |
| fuel_economy | mpg_uk; mpg |
| ratio | sr, steradian, steradians; ppm; ppb; ppt; permille, ‰; basis_point, basis_points, ‱; pcm; dozen, dozens; bakers_dozen; score, scores; gross; thousand; million; billion; trillion; quadrillion; quintillion; sextillion; septillion; octillion; nonillion; decillion; undecillion; duodecillion; tredecillion; quattuordecillion; quindecillion; sexdecillion; septendecillion; octodecillion; novemdecillion; vigintillion; centillion; milliard, milliards; billiard, billiards; googol; lakh, lakhs; crore, crores |
Functions
Section titled “Functions”simplify
Section titled “simplify”simplify(q: quantity) -> num|quantity
the quantity in the prefix of its unit that reads best, like 3.6 kW instead of 3600 W
Also written to best
10.0012 km to best1.2 m23600 J/s to best3.6 kW31 kg*m^2/s^2 to best1 J41.5e9 B.simplify1.5 GBsi(q: quantity) -> num|quantity
the quantity in standard metric (SI) units
A named one like J (joules) or N (newtons) if there is one, otherwise base units like m, kg and s. Also written to si
15 mi/h to si2.2352 m/s22 kWh to si7200000 J372 F to si295.372 KSee also simplify
kind(q: quantity) -> str
the kind of quantity, like length or force, or its SI units when the kind has no name
1(5 N).kind"force"2kind(3 km / 2 h)"speed"3(9.8 m/s^2).kind"m/s^2"all_units
Section titled “all_units”all_units() -> table
every unit zil knows, as a table
Its columns are name, full name, description, other names, kind (like length), size in SI units, and source: “units”, “informal”, “currency” or “user” for ones you defined
1all_units().len4432all_units().filter(|u| u.kind == "length").map(|u| u.name).take(5)["m", "km", "cm", "mm", "µm"]3all_units().filter(|u| u.source == "informal")[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: "informal"}See also simplify, refresh_rates
refresh_rates
Section titled “refresh_rates”refresh_rates() -> int
fetch the latest currency exchange rates now, and return how many currencies they cover
Rates are otherwise kept for the number of hours in config.rates_hours, and fetched when a currency is first used
1refresh_rates()See also all_units
db(ratio: num, kind: str = “power”) -> float
a ratio of two powers in decibels, as 10 × log10(ratio), so doubling is about +3 dB
For a ratio of voltages or sound pressures, pass “amplitude”, which uses 20 × log10
1db(2)3.01032db(1000)303db(2, "amplitude")6.0206from_db
Section titled “from_db”from_db(db: num, kind: str = “power”) -> float
decibels back to the ratio of powers, the reverse of db
With “amplitude”, the ratio of voltages or sound pressures
1from_db(3)1.995262from_db(-6, "amplitude")0.501187See also db
More examples
Section titled “More examples”1# speed from distance and time2100 km / 2 h to mph31.0686 mph3# feet and inches41.8 m to ft in"5 ft 10.8661 in"5# feet and inches written together65 ft 11 in to cm180.34 cm7# 300 miles at 65 mph8300 mi / 65 mph to h min"4 h 36.9231 min"9# downloading 4 GB at 100 Mbps104 GB / 100 Mbps to min5.33333 min11# why a 1 TB disk shows less: GiB are bigger than GB121 TB to GiB931.323 GiB13# area143 m * 4 m to ft^2129.167 ft^215# a 10 km run in an hour, as minutes per mile161 h / 10 km to min/mi9.65606 min/mi17# the force of 70 kg under gravity189.81 m/s^2 * 70 kg to N686.7 N19# a month of a 60 W bulb2060 W * 8 h * 30 to kWh14.4 kWh21# a fever in Celsius22101 F to C38.3333 C23# a 1080p screen at 96 dpi241080 px to in11.25 in25# twice the power, in decibels26db(2)3.010327# how much more power +3 dB is28from_db(3)1.99526Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.