Skip to content

Unit arithmetic

Package: UOM_PACKAGE. Registered by createEngine(); for a slimmer engine, register it explicitly (see choosing packages).

A unit is the thing a number is measured in: metres, kilograms, hours. Solve lets you write a quantity the way you would say it, and add or subtract two quantities even when they are written in different units of the same kind.

Units are case-sensitive and are never remapped, which is deliberate. m is metres and M is the millions suffix, and guessing between them would produce confidently wrong answers.

Most units have more than one spelling, and all of them work: lb, lbs and pounds are the same unit, as are m, metre and metres. What you will not get is a guess, so a spelling that is not a unit stays an error rather than being resolved to the nearest thing that looks similar.

Every spelling the engine accepts is listed on the unit reference page, which is generated by running each one through a real engine rather than by transcribing a table.

The left operand decides the result unit.

100cm + 2m // 300.00 cm
1 km + 500 m // 1.50 km