OpenWeatherMap.org’s API returns temperatures in degrees Kelvin, which is probably the best temperature scale for scientific use but is meaningless to most people in day-to-day life. Here are a couple of functions to convert it to your temperature scale of choice:
Fahrenheit
function k_to_f($temp) { if ( !is_numeric($temp) ) { return false; } return round((($temp - 273.15) * 1.8) + 32); }
Celsius/Centigrade
function k_to_c($temp) { if ( !is_numeric($temp) ) { return false; } return round(($temp - 273.15)); }
If you want to preserve decimal points, you can remove or modify the round()
function to get the level of precision you want. Personally, I’ve never found decimal places in temperatures useful day-to-day.