getValue abstract method

double getValue(
  1. T targetUnit
)

Converts this quantity's value to the specified targetUnit and returns the numerical result of this conversion.

The default implementation uses a direct linear multiplication via this.unit.factorTo(targetUnit), which is correct for all linear (non-affine) quantities. Non-linear quantities (e.g., Temperature) override this with their specific conversion formulas.

  • targetUnit: The desired unit to which the current quantity's value should be converted.

Returns the numerical value of this quantity expressed in the targetUnit.

Example:

final lengthInMeters = Length(1.0, LengthUnit.kilometer);
double meters = lengthInMeters.getValue(LengthUnit.meter); // meters will be 1000.0

final tempInCelsius = Temperature(0.0, TemperatureUnit.celsius);
double fahrenheit = tempInCelsius.getValue(TemperatureUnit.fahrenheit); // fahrenheit will be 32.0

Implementation

double getValue(T targetUnit);