To convert Celsius to Fahrenheit, multiply by 9/5 (or 1.8) and add 32: °F = °C × 9/5 + 32. So 25 °C is 77 °F. To go back, subtract 32 and divide by 1.8. Below is a quick chart, a mental shortcut, and the code in Ruby, JavaScript and Python, including the two bugs that make the results come out wrong.
Key takeaways
- Celsius to Fahrenheit: °F = °C × 9/5 + 32.
- Fahrenheit to Celsius: °C = (°F − 32) × 5/9.
- -40 is the same in both scales.
- In Ruby,
9 / 5is1. Use9.0or the result is wrong. - Round only when you display the number, never while you calculate.
What is the formula to convert Celsius to Fahrenheit?
Multiply the Celsius temperature by 9/5 and add 32. The U.S. National Institute of Standards and Technology (NIST) writes the same formula as (°C × 1.8) + 32.
°F = °C × 9/5 + 32
Example: 25 × 9/5 = 45, and 45 + 32 = 77 °F.
How do you convert Fahrenheit to Celsius?
Subtract 32 and multiply by 5/9 (or divide by 1.8).
°C = (°F − 32) × 5/9
Example: 350 °F − 32 = 318, and 318 × 5/9 ≈ 176.7 °C.
Celsius to Fahrenheit chart
| Celsius | Fahrenheit | Reference |
|---|---|---|
| -40 °C | -40 °F | Both scales match |
| -10 °C | 14 °F | Cold winter day |
| 0 °C | 32 °F | Water freezes |
| 10 °C | 50 °F | Cool day |
| 20 °C | 68 °F | Room temperature |
| 25 °C | 77 °F | Warm day |
| 30 °C | 86 °F | Hot day |
| 37 °C | 98.6 °F | Typical body temperature |
| 40 °C | 104 °F | Heat wave |
| 100 °C | 212 °F | Water boils at sea level |
| 180 °C | 356 °F | Moderate oven |
| 200 °C | 392 °F | Hot oven |
Is there a quick way to convert Celsius to Fahrenheit in your head?
Double the Celsius number and add 30. 20 °C becomes 40 + 30 = 70 °F (the exact answer is 68 °F). It’s close for everyday weather and drifts as temperatures climb, so don’t use it for cooking or a fever.
To go from Fahrenheit to Celsius, subtract 30 and halve it. 80 °F becomes 50 / 2 = 25 °C (exact: 26.7 °C).
How do you convert Celsius to Fahrenheit in Ruby?
Use a float in the formula: celsius * 9.0 / 5 + 32.
def celsius_to_fahrenheit(celsius)
celsius * 9.0 / 5 + 32
end
def fahrenheit_to_celsius(fahrenheit)
(fahrenheit - 32) * 5.0 / 9
end
celsius_to_fahrenheit(37) # => 98.6
fahrenheit_to_celsius(350) # => 176.66666666666666
Watch out for integer division. In Ruby, dividing two integers returns an integer, so 37 * 9 / 5 + 32 gives 98 instead of 98.6. Make one side a float (9.0), or use a rational (9r / 5) and call .to_f at the end.
How do you convert Celsius to Fahrenheit in JavaScript?
Use the formula directly: celsius * 9 / 5 + 32.
const celsiusToFahrenheit = (celsius) => celsius * 9 / 5 + 32;
const fahrenheitToCelsius = (fahrenheit) => (fahrenheit - 32) * 5 / 9;
celsiusToFahrenheit(37); // 98.6
JavaScript numbers are floating point by default, so integer division isn’t a problem here.
How do you convert Celsius to Fahrenheit in Python?
Use the formula directly: celsius * 9 / 5 + 32.
def celsius_to_fahrenheit(celsius):
return celsius * 9 / 5 + 32
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
celsius_to_fahrenheit(37) # 98.6
In Python 3, / always returns a float. Python 2 had the same integer division trap as Ruby, which PEP 238 changed.
Why does my conversion return 97.88000000000001?
Because computers store most decimals as approximations. In all three languages, 36.6 * 9 / 5 + 32 returns 97.88000000000001, not 97.88. The Python docs explain why. Round when you display the value, not while you calculate:
celsius_to_fahrenheit(36.6).round(1) # => 97.9
Math.round(celsiusToFahrenheit(36.6) * 10) / 10; // 97.9
round(celsius_to_fahrenheit(36.6), 1) # 97.9
Frequently asked questions
At what temperature are Celsius and Fahrenheit equal?
At -40. Plug -40 into either formula and you get -40 back.
What is 37 °C in Fahrenheit?
98.6 °F, the textbook normal body temperature.
What is 350 °F in Celsius?
About 176.7 °C. Recipes usually round it to 175 or 180 °C.
Is the formula 9/5 or 1.8?
Both. 9/5 equals 1.8 exactly, so °C × 1.8 + 32 gives the same result.
The bottom line
Multiply by 9/5 and add 32. In code, the formula is the easy part: use a float, and round only when you show the result.
MagmaLabs is a senior engineering team in Mexico that has shipped Rails, React, Node and Python apps for US companies since 2011. Need engineers who catch the small bugs before they ship? Book a 30-minute call.