Convert & format
Convert between units and render values back.
Prefer the live demos? Open this section in the interactive docs.
Convert between units with exact legal factors (temperature deltas included), then render values back with best-fit and compound output. Everything format() emits re-parses to the same value.
import { convert, convertDelta, tryConvert, quantity } from "@pascal-app/lingo"
convert(72, "in", "ft") // 6 (exact legal factors)
convert(1, "gal", "L") // 3.785411784
convertDelta(5, "C", "F") // 9 (a difference, not 41)
const targetUnit: string = "cm" // a dynamic ref (the escape hatch)
tryConvert(5, "kg", targetUnit) // { ok: false, issues } instead of throwing
quantity(1500, "m").toBest().format() // "1.5 km"
quantity(1.8034, "m").format({ compound: ["ft", "in"] }) // "5′11″"
quantity(2, "ft").format({ style: "long" }) // "2 feet"convert throws on a bad pair; tryConvert returns a structured issue instead. convertDelta converts a difference — a 5 °C rise is a 9 °F rise, not 41.