Kodeclik Blog


How to convert Fahrenheit to Celsius

The Fahrenheit scale is a temperature scale based on a system proposed in 1724 by the physicist Daniel Gabriel Fahrenheit.
Fahrenheit based his scale on three points: the stabilizing point of water, ice, and ammonium chloride as 0°F, the point at which still water just began to form ice on its surface as 32°F, and the temperature of the human body taken in the mouth or under the arm as 96°F. Later, scientists readjusted the scale to make the interval between the freezing and boiling points of water exactly 180°, and the human body temperature moved from 96°F to 98.6°F.
The Fahrenheit scale is used in the United States, and its colonies and territories, and a few other small nations.
The Celsius scale, on the other hand, is employed in most other countries and for scientific purposes worldwide. It was invented 18 years after the Fahrenheit scale. The Celsius scale is based on 0 degrees for the freezing point and 100 degrees for the boiling point of water.
The conversion formula from Fahrenheit to Celsius is °C = 5/9 × (°F - 32). Try the below form out to get the hang of this formula!

Convert Fahrenheit to Celsius

(Type in either textbox to convert)

Converting Fahrenheit to Celsius in Javascript

Let us write a simple Javascript program and embed it in a form so you can use it to do your own calculations! This program is a vanilla one so it doesn't have styling, error catching, etc.
This code creates a simple HTML form with a label, an input textbox, and a button. When the button is clicked, the convert() function is called. This function retrieves the value of the input textbox, converts it to the desired scale, and displays the result in a paragraph element with the id "result". As mentioned earlier, the conversion is done by our simplel formula above. The form and results will look like:
Note that this code assumes that the input is a valid number. It does not perform any input validation or error handling. Don’t try silly things like negative numbers - it will work but the results are not particularly meaningful. Similarly if you give a non-number as input it will result in NaN results (Not a Number).

Converting Fahrenheit to Celsius in Python

Here's a Python function that does our conversion for us:
Pretty simple, isn't it?
Here are some examples of using this Python function:
There are other ways to convert temperatures in Python, such as using specialized modules for working with units. However, the function we have written is a simple and straightforward way to perform this conversion.
Now that you have learnt how to convert Fahrenheit to Celsius, learn to do the reverse, i.e., convert Celsius to Fahrenheit!
Want to learn Javascript or Python with us? Sign up for 1:1 or small group classes.

Join our mailing list

Subscribe to get updates about our classes, camps, coupons, and more.
  • ABOUT

Copyright @ Kodeclik 2023. All rights reserved.