convert
Convert a value from one unit to another across all measurement categories. Supports compound expressions and returns the converted magnitude with unit and exactness flag.
Instructions
Convert a value or unit expression from one unit to another (GNU units engine, TODO §16).
The universal conversion core: one tool covers every category (length, mass,
time, temperature, area, volume, energy, power, speed, data, …) plus compound
expressions like kW*h or acre*ft. Linear conversions return the ratio of
coefficients; a nonlinear target (e.g. tempF) applies that unit's inverse.
Returns: from and to (echoed), result (the converted magnitude WITH the
target unit, e.g. "1.609344 km" — the primary human-readable answer), value
(the same magnitude as a bare float for programmatic use), and exact (true
when the result is exact, false when it was rounded).
Errors cleanly (isError) when a unit is unknown, an expression is malformed,
or the two sides are not conformable.
Example: convert("1 mile", "km") ->
{"from":"1 mile","to":"km","result":"1.609344 km","value":1.609344,"exact":true}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to_expr | Yes | The unit expression to convert TO, e.g. 'km', 'gallons', 'joule', 'tempF'. Must be dimensionally conformable with `from_expr` (both length, both energy, …) or a nonlinear target such as 'tempF'; otherwise the call errors. Use find_units to discover the exact spelling of a unit. | |
| from_expr | Yes | The quantity or unit expression to convert FROM. May carry a numeric coefficient and be a compound expression: '2.5 acre*ft', '55 mile/hour', 'kW*h', '0 tempC'. A bare unit like 'mile' is treated as one of that unit. |