Unit.to()method
Convert an amount from this unit to another unit.
to(amount: number, targetKey?: K): number
new Unit<K>(list: UnitList<K>, key: K, { to, ...options }: UnitProps<K>)| Param | Type | |
|---|---|---|
list | UnitList<K> | UnitList this unit belongs to. required |
key | K | String key for this unit, e.g. kilometer. required |
props | UnitProps<K> | Props to configure this unit (conversions and formatting options). required |
| Return | |
|---|---|
Unit<K> | Represent a single unit of measure within a UnitList, e.g. kilometer. |
| Property | Type | |
|---|---|---|
.list | UnitList<K> | |
.key | K | String key for this unit, e.g. kilometer required readonly |
.options | Readonly<UnitFormatOptions> | Possible options for formatting these units. readonly |
Represent a single unit of measure within a UnitList, e.g. kilometer.
LENGTH_UNITS.require("kilometer").to(5, "meter") // 5000Convert an amount from this unit to another unit.
to(amount: number, targetKey?: K): number
Convert an amount from another unit to this unit.
from(amount: number, sourceKey?: K): number
Format an amount with a given unit of measure, e.g. 12 kg or 29.5 l
format(amount: number, options?: UnitFormatOptions): string