Method Deck / units

Volume conversion

Converts a volume between metric units and US customary or UK imperial volume units.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Look up the exact liter-equivalent of from_unit and of to_unit from the US customary / UK table.
  2. Convert the input to liters: liters = value * liters_per(from_unit).
  3. Convert liters to the target unit: result = liters / liters_per(to_unit).
  4. Round result to 6 significant figures.

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"value":1,"from_unit":"gallon_us","to_unit":"L"}3.78541 L
test vector: cups to fluid ounces{"value":1,"from_unit":"cup_us","to_unit":"fl_oz_us"}8.00000 fl oz (US)
test vector: UK gallon to liters{"value":1,"from_unit":"gallon_uk","to_unit":"L"}4.54609 L

Published card