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 (e.g., Length, Pressure), this involves a direct multiplication by a conversion factor: convertedValue = this.value * this.unit.factorTo(targetUnit).

For quantities with affine conversions (like Temperature with Celsius or Fahrenheit), subclasses must implement specific conversion formulas that account for offsets (e.g., (value * 9/5) + 32 for Celsius to Fahrenheit).

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