You are here

public static function LengthUnit::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/LengthUnit.php, line 43

Class

LengthUnit
Provides length units.

Namespace

Drupal\physical

Code

public static function getBaseFactor($unit) {
  self::assertExists($unit);
  $factors = [
    self::MILLIMETER => '0.001',
    self::CENTIMETER => '0.01',
    self::METER => '1',
    self::KILOMETER => '1000',
    self::INCH => '0.0254',
    self::FOOT => '0.3048',
    self::NAUTICAL_MILE => '1852',
  ];
  return $factors[$unit];
}