转换

自动将华氏度等值转换为摄氏度或摄氏度。

示例 3-1 摄氏度到华氏度转换

//given temperature in C, convert to F and return converted value

var fahrenheit;
fahrenheit = (celsius * (9/5)) + 32;
return Number(fahrenheit);

使用内嵌计算的示例 3-2 摄氏度到华氏度转换(简化)

//given temperature in C, returning converted value to F using inline calculation

return (tempc * (9/5)) + 32;

示例 3-3:使用内嵌计算将华氏度转换为摄氏度

//given temperature in F, returning converted value to C using inline calculation

return (tempf - 32) * 5/9);