Skip to content

编程实现温度转换,已知温度转换的关系式是:华氏度=32+摄氏度×1.8,现在要求输入摄氏度,输出对应的华氏度,小数保留两位

参考答案:

js
function convertTemperature(centigrade){
   if(typeof centigrade !== 'number'){
   	throw new Error('Wrong parameter type!')
   }

   return (32 + centigrade * 1.8).toFixed(2)
}