PHP Program to convert fahrenheit to celsius

February 15, 2024, Learn eTutorial
2498

Fahrenheit to Celsius

In this program, we are converting the temperature in Fahrenheit to Celsius.

To convert Fahrenheit to Celsius we use the formula '(F − 32) × 5/9 = C'. For example, if the user entered value in Fahrenheit is 56 then the formula will be (56°F − 32) × 5/9 and the result will be 13.333°C.

How to convert Fahrenheit to Celsius using PHP

In this program, we are using the direct method to convert the temperature in Fahrenheit to celsius. First, we read the Fahrenheit value from the user and store it in the variable and then apply it to the formula to find the temperature in celsius.

ALGORITHM

Step 1: Accept the Fahrenheit from the user and store it to the variable fahrenheit

Step 2: Assign the calculate value of '((fahrenheit - 32) * 5) / 9' to the variable celsius

Step 3: Print the value of the variable celsius as the celsius value of entered Fahrenheit

PHP Source Code

```                                          ```<?php
\$fahrenheit = readline("Enter the fahrenheit: ");
\$celsius = ((\$fahrenheit - 32) * 5) / 9;
\$celsius = round(\$celsius, 3);              // round() is used to limit the number of digit after the decimal
echo "Temperature in celsius is: \$celsius";
?>```
```

OUTPUT

```Enter the fahrenheit: 78
Temperature in celsius is: 25.556```

VIEW ALL
VIEW ALL