Docs / Unit conversion

Unit conversion

Unit conversion fails less often through arithmetic than through names. A gallon is 3.785 litres in the United States and 4.546 in the United Kingdom. A ton can be a metric tonne, a short ton of 2,000 pounds or a long ton of 2,240. A megabyte is a million bytes on a disk label and 1,048,576 bytes in many operating systems. A converter that picks one meaning without saying so produces a number that is exactly right for a unit nobody asked about.

Here every unit has one meaning. A name that could mean several units, such as ton, is refused with the alternatives listed, and the answer to a conversion repeats the full name of both units, so there is no doubt about which gallon was used. Coefficients come from the SI definitions and from the international agreements that define customary units in SI terms, and where a conversion is exact the answer says so.

Temperature is the other trap in the group. Converting 20 degrees Celsius to Fahrenheit is not the same operation as converting a rise of 20 degrees, because the scales have different zero points. Absolute temperatures and temperature differences are therefore separate units, and a conversion between absolute temperatures carries a note naming the units for differences.

/convert/units lists every unit by dimension, with its aliases.

Every endpoint in this group

/convert/{value}/{from}/{to}?[precision=]

Convert a value between units (exact SI coefficients)

value: decimal number; from: unit symbol, e.g. km, lb, C, psi, MiB; units containing '/' need %2F or the query form; to: unit symbol; precision (optional): significant digits when the result does not terminate

curl "https://agent-helper.org/convert/10/km/mi"

/convert?value=&from=&to=&[precision=]

Convert a value between units (query form, for units such as km/h)

value: decimal number; from: unit; to: unit; precision (optional): significant digits when the result does not terminate

curl "https://agent-helper.org/convert?value=100&from=km/h&to=mph"

/convert/units

Every supported unit by dimension, with aliases

curl "https://agent-helper.org/convert/units"