Unit Converter

Dr. Johannes W. Dietrich, M.D.

The Unit Converter is a Pascal unit that provides functions for parsing measurements consisting of measurement values and units. It also supports conversion of measurements from one unit to another one.

Briefly, it provides the following data structures and functions:

type
  tMeasurement = record
    Value: extended;
    uom: string;
  end;
  tUnitElements = record
       MassPrefix, MassUnit, VolumePrefix, VolumeUnit: String;
  end;  
  TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber,
  ffCurrency);
  PrefixLabel: array[0..MAXFACTORS - 1] of string;
  PrefixFactor: array[0..MAXFACTORS - 1] of real;
  UnitLabel: array[0..MAXFACTORS - 1] of string;

function DecodeGreek(theString: string): string;
function EncodeGreek(theString: string): string;
function ParsedUnitString(theString: String): TUnitElements;
function ParsedMeasurement(measurement: string): tMeasurement;
function ConvertedValue(value, molarMass: real; fromUnit, toUnit: string): real;
function ValueFromUnit(fromValue: string; molarMass: real; toUnit: string): real;
function UnitFromValue(value, molarMass: real; fromUnit, toUnit: string): string;
function UnitFromValueF(value, molarMass: real; fromUnit, toUnit: string; format: TFloatFormat; precision, digits: integer): string;
function ConvertedUnit(fromValue: string; molarMass: real; toUnit: string): string;
function ConvertedUnitF(fromValue: string; molarMass: real; toUnit: string; format: TFloatFormat; precision, digits: integer): string;


  • DecodeGreek: decodes an ASCII substitution sequence ("mc") for the greek mu letter.

  • EncodeGreek: encodes an ASCII substitution sequence for the greek mu letter.

  • ParsedUnitString: parses a string for measurement unit and breaks it up into single components of a TUnitElements record.

  • ParsedMeasurement : decompose measurement result into numeric value and unit.

  • ConvertedValue: converts value delivered as a real number from one measurement unit to another one. Returns a real number.

  • ValueFromUnit: converts value from one measurement unit to another one and delivers numeric result.

  • UnitFromValue: converts value delivered as a real number to measurement with unit.

  • UnitFromValueF: Similar to UnitFromValue, but delivers formatted output.

  • ConvertedUnit: converts value from one measurement unit to another one and delivers string with result.

  • ConvertedUnitF: Similar to ConvertedUnit, but delivers formatted output.


Detailled information is available in the full Unit Converter Documentation (PDF download).


Related

Wiki: Home