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.

This method must be implemented by concrete subclasses.

For most quantities, this involves a direct multiplication by a conversion factor obtained from this.unit.factorTo(targetUnit). Subclasses like Temperature override this to implement specific conversion formulas (e.g., for affine transformations).

  • 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);