You are here

public static function WeightUnit::getBaseFactor in Physical Fields 8

Gets the base factor for the given unit.

Used for converting measurements to and from the base unit. Use multiplication to convert a measurement to the base unit, and division to convert from the base unit (into the given unit).

Parameters

string $unit: The unit.

Return value

string The base factor.

Overrides UnitInterface::getBaseFactor

File

src/WeightUnit.php, line 39

Class

WeightUnit
Provides weight units.

Namespace

Drupal\physical

Code

public static function getBaseFactor($unit) {
  self::assertExists($unit);
  $factors = [
    self::MILLIGRAM => '0.000001',
    self::GRAM => '0.001',
    self::KILOGRAM => '1',
    self::OUNCE => '0.028349523125',
    self::POUND => '0.45359237',
  ];
  return $factors[$unit];
}