Method Deck / units

Temperature conversion

Converts a temperature between Celsius, Fahrenheit, Kelvin, and Rankine using the exact NIST SP 811 defining formulas.

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

Try it

Inputs

Outputs

Steps

  1. Convert the input to Celsius: C=C if from_unit is C; C=(F-32)*5/9 if F; C=K-273.15 if K; C=(R-491.67)*5/9 if R (since R=F+459.67).
  2. Convert Celsius to the target unit: F=C*9/5+32; K=C+273.15; R=(C+273.15)*9/5; C=C.
  3. Round the result to 2 decimal places (the conventional precision for temperature).

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"value":100,"from_unit":"C","to_unit":"F"}212.00 deg F
test vector: freezing point to Kelvin{"value":0,"from_unit":"C","to_unit":"K"}273.15 deg K
test vector: body temperature to Celsius{"value":98.6,"from_unit":"F","to_unit":"C"}37.00 deg C

Published card