您可以使用以下公式将摄氏度值转换为华氏度:
fahrenheit = celsius * 1.8 + 32
示例: 摄氏到华氏
// program to convert celsius to fahrenheit // ask the celsius value to the user const celsius = prompt("Enter a celsius value: "); // calculate fahrenheit const fahrenheit = (celsius * 1.8) + 32 // display the result console.log(`${celsius} degree celsius is equal to ${fahrenheit} degree fahrenheit.`);
输出
Enter a celsius value: 55 55 degree celsius is equal to 131 degree fahrenheit.
在上面的程序中,用户输入celsius值并存储在
celsius变量中。然后使用华氏公式将摄氏度值转换为华氏度。
您可以使用以下公式将华氏度值转换为摄氏度:
celsius = (fahrenheit-32) / 1.8