Skip to content

Instantly share code, notes, and snippets.

@micheltlutz
Created August 10, 2017 14:03
Show Gist options
  • Save micheltlutz/8cb8f30798a7e807a447cbe7bf09110a to your computer and use it in GitHub Desktop.
Save micheltlutz/8cb8f30798a7e807a447cbe7bf09110a to your computer and use it in GitHub Desktop.
Swift 3 Double Extensions
extension Double
{
/**
* Calc Celcius to Fahrenheit
* @return Double value in Fahrenheit
*/
func celsiusToFahrenheit() -> Double
{
return self * 9 / 5 + 32
}
/**
* Calc Fahrenheit to Celcius
* @return Double value in Celcius
*/
func fahrenheitToCelsius() -> Double
{
return (self - 32) * 5 / 9
}
}
@micheltlutz
Copy link
Author

Usage

var temperatura = 16.5
print(temperatura.celsiusToFahrenheit())
print(temperatura.fahrenheitToCelsius())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment