Quantity

Quantity

Class allowing easy Units of Measurement/Quantity handling by wrapping the openHAB QuantityType.

Throws QuantityError if Quantity creation or operation failed. Throws TypeError if wrong argument type is provided.

Members

dimension :string

Source:

Dimension of this Quantity, e.g. [L] for metres or [L]² for cubic-metres

Type:
  • string

unit :string|null

Source:

Unit of this Quantity, e.g. Metre, or null if not available

Type:
  • string | null

symbol :string|null

Source:

Unit symbol of this Quantity, e.g. m, or null if not available

Type:
  • string | null

float :number

Source:

Float (decimal number) value of this Quantity

Type:
  • number

int :number

Source:

Integer (non-decimal number) value of this Quantity

Type:
  • number

Methods

add(value) → {Quantity}

Source:

Add the given value to this Quantity.

Parameters:
Name Type Description
value string | Quantity

string consisting of amount and unit or a Quantity

Returns:

result as new Quantity

Type
Quantity

divide(value) → {Quantity}

Source:

Divide this Quantity by the given value.

Example
Quantity('20 W').divide(4); // is 5 W
Quantity('20 W').divide('4 W') // is 5
Parameters:
Name Type Description
value number | string | Quantity

usually a number; may also be a string consisting of amount and unit or a Quantity, but be careful: 1 W / 5 W = 0.2 which might not be what you want

Returns:

result as new Quantity

Type
Quantity

multiply(value) → {Quantity}

Source:

Multiply this Quantity by the given value.

Example
Quantity('20 W').multiply(4); // is 80 W
Quantity('20 W').multiply('4 W') // is 80 W^2
Parameters:
Name Type Description
value number | string | Quantity

usually a number; may also be a string consisting of amount and unit or a Quantity, but be careful: 1 W * 5 W = 5 W^2 which might not be what you want

Returns:

result as new Quantity

Type
Quantity

subtract(value) → {Quantity}

Source:

Subtract the given value from this Quantity.

Parameters:
Name Type Description
value string | Quantity

string consisting of amount and unit or a Quantity

Returns:

result as new Quantity

Type
Quantity

toUnit(unit) → {Quantity|null}

Source:

Convert this Quantity to the given unit.

Parameters:
Name Type Description
unit string
Returns:

a new Quantity with the given unit or null if conversion to this unit is not possible

Type
Quantity | null

equal(value) → {boolean}

Source:

Checks whether this Quantity is equal to the passed in value.

Parameters:
Name Type Description
value string | Quantity
Returns:
Type
boolean

greaterThan(value) → {boolean}

Source:

Checks whether this Quantity is larger than the passed in value.

Parameters:
Name Type Description
value string | Quantity
Returns:
Type
boolean

greaterThanOrEqual(value) → {boolean}

Source:

Checks whether this Quantity is larger than or equal to the passed in value.

Parameters:
Name Type Description
value string | Quantity
Returns:
Type
boolean

lessThan(value) → {boolean}

Source:

Checks whether this Quantity is smaller than the passed in value.

Parameters:
Name Type Description
value string | Quantity
Returns:
Type
boolean

lessThanOrEqual(value) → {boolean}

Source:

Checks whether this Quantity is smaller than or equal to the passed in value.

Parameters:
Name Type Description
value string | Quantity
Returns:
Type
boolean