Convert Fahrenheit to Celsius in JavaScript

In this tutorial, we will see how to convert Fahrenheit to Celsius in JavaScript.

This is a pure mathematical program in which we can apply the formula of conversion and then convert the desired value from Fahrenheit to Celsius and vice versa.

Fahrenheit to Celsius

Using this formula celsius = (fahrenheit - 32) / 1.8 we can create a function that will do the conversion.

function fahrenheitToCelsius(val){
  return (val - 32) / 1.8;
}

fahrenheitToCelsius(96); 
//35.55555555555556

Celsius to Fahrenheit in JavaScript

Similary, we can alter the formula and get the Fahrenheit from the celsius fahrenheit = celsius * 1.8 + 32.

function celsiusToFahrenheit(val){
  return (val * 1.8) + 32;
}

celsiusToFahrenheit(35.55555555555556); 
//96

Based on your requirements, you can round off the returned value from the functions.