Celsius to Fahrenheit
In order to convert from Celsius to Fahrenheit, you can use the conversion formula F = 1.8 * C + 32
.
代码实现
const celsiusToFahrenheit = degrees => 1.8 * degrees + 32;
celsiusToFahrenheit(33); // 91.4
Fahrenheit to Celsius
Conversely, the conversion formula from Fahrenheit to Celsius is C = (F - 32) * 5 / 9
.
使用样例
const fahrenheitToCelsius = degrees => (degrees - 32) * 5 / 9;
fahrenheitToCelsius(32); // 0
翻译自:https://www.30secondsofcode.org/js/s/convert-celsius-fahrenheit