Unit

protected constructor(baseUnit: U, toBaseConverter: UnaryFunction, fromBaseConverter: UnaryFunction, name: String, symbol: String)

Creates a new unit defined by its relationship to some base unit.

Parameters

baseUnit

the base unit, e.g. Meters for distances. Set this to null if the unit being constructed is its own base unit

toBaseConverter

a function for converting units of this type to the base unit

fromBaseConverter

a function for converting units of the base unit to this one

name

the name of the unit. This should be a singular noun (so "Meter", not "Meters")

symbol

the short symbol for the unit, such as "m" for meters or "lb." for pounds


protected constructor(baseUnit: U, baseUnitEquivalent: Double, name: String, symbol: String)

Creates a new unit with the given name and multiplier to the base unit.

Parameters

baseUnit

the base unit, e.g. Meters for distances

baseUnitEquivalent

the multiplier to convert this unit to the base unit of this type. For example, meters has a multiplier of 1, mm has a multiplier of 1e3, and km has multiplier of 1e-3.

name

the name of the unit. This should be a singular noun (so "Meter", not "Meters")

symbol

the short symbol for the unit, such as "m" for meters or "lb." for pounds