The United States is one of the last bodies that refuses to implement the Celsius temperature standard. Why? Because we’re arrogant and feel like we don’t need to change. With that said, if you code for users outside the US, it’s important to provide localized weather data to users. Let’s took at how you can convert between Fahrenheit and Celsius.
Fahrenheit to Celsius
The formula to convert Fahrenheit to Celsius is:
°C = 5/9 x (°F - 32)
The following function converts Fahrenheit to Celsius:
function convertFahrenheitToCelsius(degrees) return Math.floor(5 / 9 * (degrees - 32));
Celsius to Fahrenheit
The formula to convert Celsius to Fahrenheit is:
°F = (°C × 9/5) + 32
The following function converts Celsius to Fahrenheit:
function convertCelsiusToFahrenheit(degrees) return Math.floor(degrees * (9/5) + 32);
Temperature conversion is one of those things that’s difficult to do in your head due to the somewhat complex formula. If you have a site that reflects weather data, keep these handy functions nearby!
Vibration API
Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user. One of those simple APIs the Vibration API. The Vibration API allows developers to direct the device, using JavaScript, to vibrate in…
JavaScript Canvas Image Conversion
At last week’s Mozilla WebDev Offsite, we all spent half of the last day hacking on our future Mozilla Marketplace app. One mobile app that recently got a lot of attention was Instagram, which sold to Facebook for the bat shit crazy price of one…
Source link