valueInUnits method

Number valueInUnits(
  1. Units? units
)

Gets the Quantity's value in the specified units. If units is null, the MKS value is returned. If not null, units must have dimensions compatible with this Quantity or a DimensionsException will be thrown.

Implementation

Number valueInUnits(Units? units) {
  if (units == null) {
    return mks;
  } else {
    // First check for compatible dimensions
    if (units is Quantity && (units as Quantity).dimensions == dimensions) {
      return units.fromMks(valueSI);
    } else {
      throw DimensionsException('Cannot retrieve quantity value using units with incompatible dimensions');
    }
  }
}