formula for converting fahrenheit to celsius code example

Example 1: fahrenheit to celsius formula

cels = (fahr - 32.0) * 5.0/9.0; //Fahr to cels
fahr = (cels * 9.0/5.0) + 32.0; //Cels to fahr

Example 2: different formulas to convert celsius to fahrenheit

function fahrenheitToCelsius(fahrenheit) {
  return (((fahrenheit - 32) * 5) / 9).toFixed(1);
} // Using toFixed returns a decimal value

function celsiusToFahrenheit(celsius) {
  return ((9 * celsius) / 5 + 32).toFixed(1);
} // Better to multiply in this order for celsius

Example 3: celsius to fahrenheit formula

fahr = celsius * (9.0/5.0) + 32.0;

Tags:

C Example