Quantity class

An immutable numerical quantity with an associated Unit.

Supports arithmetic operations, unit conversions, and comparisons.

final length = Quantity.of(30, meters);
final time   = Quantity.of(10, seconds);
final speed  = length / time; // 3 m/s
Implemented types
Implementers

Constructors

Quantity.of(num value, Unit unit)
Creates a quantity with the given value and unit.
const
Quantity.zero(Unit unit)
Creates a zero-valued quantity with the given unit.
const

Properties

dimensions Dimensions
The dimensions of (the units of) this quantity.
no setter
hashCode int
The hash code for this object.
no setteroverride
isNegative bool
Whether the value stored in this quantity is negative.
no setter
isScalar bool
Whether this quantity is a scalar (dimensionless).
no setter
isScalarSI bool
Whether this quantity is a scalar (dimensionless) in the strict SI sense.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sign num
The sign of the value stored in this quantity.
no setter
unit Unit
final
value num
final
valueSI num
The value of this quantity in SI base scaled units.
no setter

Methods

abs() Quantity
An absolute value copy of this quantity.
cbrt() Quantity
A cube rooted copy of this quantity.
ceil() Quantity
A ceiled copy of this quantity.
compareTo(Quantity other) int
Compares this quantity to other in common units.
override
cubed() Quantity
A cubed copy of this quantity.
floor() Quantity
A floored copy of this quantity.
inDimensionsMaybeInverse(Dimensions other) Quantity
Converts this quantity to different dimensions, inverting if necessary.
inUnits(Unit other) Quantity
Converts this quantity to a different unit.
inUnitsMaybeInverse(Unit other) Quantity
Converts this quantity to a different unit, inverting dimensions if necessary.
inverse() Quantity
An inverted copy of this quantity, inverting both the value and unit.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
round() Quantity
A rounded copy of this quantity.
scaled(Object scalar) Quantity
A copy of this quantity scaled by scalar.
sqrt() Quantity
A square rooted copy of this quantity.
squared() Quantity
A squared copy of this quantity.
toNameString() String
The shortest string that correctly represents this quantity including its unit name.
toNameStringAsFixed(int fractionDigits) String
A decimal-point string representation of this quantity with its unit name.
toPrecision(int fractionDigits) Quantity
A copy of this quantity with its value rounded to fractionDigits decimal places.
toString() String
The shortest string that correctly represents this quantity including its unit symbol.
override
toStringAsFixed(int fractionDigits) String
A decimal-point string representation of this quantity with its unit symbol.
toStringAsFixedNoTrailing(int fractionDigits) String
A decimal-point string representation of this quantity (without trailing zeros) with its unit symbol.
truncate() Quantity
A truncated copy of this quantity.

Operators

operator *(Object multiplier) Quantity
Multiplies two quantities, deriving a new unit.
operator +(Quantity addend) Quantity
Adds two quantities, converting addend to the units of this quantity.
operator -(Quantity subtrahend) Quantity
Subtracts two quantities, converting subtrahend to the units of this quantity.
operator /(Object divisor) Quantity
Divides two quantities, deriving a new unit.
operator <(Quantity other) bool
Whether this quantity is numerically smaller than other in common units.
operator <=(Quantity other) bool
Whether this quantity is numerically smaller than or equal to other in common units.
operator ==(Object other) bool
Test whether this quantity is equal to other.
override
operator >(Quantity other) bool
Whether this quantity is numerically larger than other in common units.
operator >=(Quantity other) bool
Whether this quantity is numerically larger than or equal to other in common units.
operator [](Unit other) Quantity
Converts this quantity to a different unit.
operator ^(Object exponent) Quantity
Raises this quantity to a power, raising the unit to the same power.
operator unary-() Quantity
A negated copy of this quantity.