Quantity

Represents a dimensive quantity. Quantities have two parts: 1. value, or magnitude 2. UnitExpression, which indicates the units attached to the value.

Methods

convertTo(newUnits) → {Quantity}

Converts this Quantity to another Quantity in the given units or System. `newUnits` may be the name of a defined Unit, the name of a defined System, an instance of Unit, or an instance of System. This method provides an OO-flavored API that directly corresponds to the Functional-flavored `Sr.convert(quantity, targetUnitsOrSystem)`.
Parameters:
Name Type Description
newUnits string | Unit | UnitExpression | System
Returns:
Quantity

dividedBy(rhs) → {Quantity}

Divides this Quantity by another Quantity and returns the result as a new Quantity. No unit conversion is performed on the divisor `rhs`.
Parameters:
Name Type Description
rhs Quantity the Quantity by which to divide this Quantity.
Returns:
Quantity

minus(rhs) → {Quantity}

Subtracts another Quantity from this Quantity and returns the result as a new Quantity. If the subtractend `rhs` is not expressed in the same units as this Quantity, `rhs` will be converted to the same units as this Quantity. If `rhs` cannot be converted to the same units as this Quantity, (because, say, the Quantities are not dimensionally compatible) an Error is thrown.
Parameters:
Name Type Description
rhs Quantity a dimensionally-compatible Quantity to subtract from this Quantity.
Returns:
Quantity

plus(rhs) → {Quantity}

Adds another Quantity to this Quantity and returns the result as a new Quantity. If the addend `rhs` is not expressed in the same units as this Quantity, `rhs` will be converted to the same units as this Quantity. If `rhs` cannot be converted to the same units as this Quantity, (because, say, the Quantities are not dimensionally compatible) an Error is thrown.
Parameters:
Name Type Description
rhs Quantity a dimensionally-compatible Quantity to add to this Quantity.
Returns:
Quantity

times(rhs) → {Quantity}

Multiplies this Quantity by another Quantity and returns the result as a new Quantity. No unit conversion is performed on the multiplicand `rhs`.
Parameters:
Name Type Description
rhs Quantity the Quantity by which to multiply this Quantity.
Returns:
Quantity

toString() → {string}

Returns a string representation of this Quantity, including the `value()` and the symbolic representation of `expression()`. For instance, a Quantity representing "four meters" will be rendered "4m".
Returns:
string

units() → {UnitExpression}

Returns the UnitExpression associated with this Quantity. For example, given a Quantity representing "four meters per second", this method returns a UnitExpression representing "meters per second."
Returns:
UnitExpression

value() → {number}

Returns the scalar value associated with this Quantity. For example, given a Quantity representing "four meters per second", this method returns the number 4.
Returns:
number