|
Convert Celsius to Fahrenheit Jsp function temp2celsius ($fahrenheit, $precision = 0) { // Convert the supplied temperature in celsius to // fahrenheit and return the value. Specify the required // precision to round the converted value to. // Returns FALSE on error. if (!isset($fahrenheit)) return FALSE; $precision = (integer)$precision; $celsius = (float)(($fahrenheit - 32) / 1.8 ); return round($celsius, $precision); } function temp2fahrenheit ($celsius, $precision = 0) { // Convert the supplied temperature in fahrenheit to // celsius and return the value. Specify the required // precision to round the converted value to. // Returns FALSE on error. if (!isset($celsius)) return FALSE; $precision = (integer)$precision; $fahrenheit = (float)(1.8 * $celsius) + 32; return round($fahrenheit, $precision); } echo "50F is " . temp2celsius(50) . "C "; echo "50C is " . temp2fahrenheit(50) . "F "; ?> |