Method Deck / units

Length conversion

Converts a length between metric and US/imperial units using exact NIST SP 811 meter-equivalents.

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 meter-equivalent of from_unit and of to_unit from the NIST SP 811 table.
  2. Convert the input to meters: meters = value * meters_per(from_unit).
  3. Convert meters to the target unit: result = meters / meters_per(to_unit).
  4. Round result to 6 significant figures.

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"value":5,"from_unit":"mi","to_unit":"km"}8.04672 km
test vector: km to miles{"value":100,"from_unit":"km","to_unit":"mi"}62.1371 mi
test vector: inches to centimeters{"value":12,"from_unit":"in","to_unit":"cm"}30.4800 cm

Published card