Skip to content

Instantly share code, notes, and snippets.

@CallumWatkins
Last active February 3, 2019 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CallumWatkins/e883d59a8909aeadff982217428715d2 to your computer and use it in GitHub Desktop.
Save CallumWatkins/e883d59a8909aeadff982217428715d2 to your computer and use it in GitHub Desktop.
Functions to convert between the Kelvin, Celsius and Fahrenheit temperature scales. License: MIT
public static class TemperatureConversions
{
public static double KelvinToCelsius(double kelvin)
{
return kelvin - 273.15;
}
public static double KelvinToFahrenheit(double kelvin)
{
return kelvin * 1.8 - 459.67;
}
public static double CelsiusToFahrenheit(double celsius)
{
return celsius * 1.8 + 32;
}
public static double CelsiusToKelvin(double celsius)
{
return celsius + 273.15;
}
public static double FahrenheitToCelsius(double fahrenheit)
{
return (fahrenheit - 32) / 1.8;
}
public static double FahrenheitToKelvin(double fahrenheit)
{
return (fahrenheit + 459.67) / 1.8;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment