Skip to content

getBestUnit

function getBestUnit(value, unit): {
unit: string;
value: number;
};

Defined in: packages/engine/src/uom/UomConverter.ts:292

Convert value (in unit) to whichever unit of the same measure gives the most human-readable magnitude, e.g. 1500 metres becomes 1.5 km. Falls back to returning value/unit unchanged if unit isn’t recognized, which is what every extended unit and workday does.

Note the chosen unit is drawn from the best-unit lists, which are not restricted to spellings the lexer accepts: 0.5 l reports “mL”.

ParameterType
valuenumber
unitstring
{
unit: string;
value: number;
}
unit: string;
value: number;