celsiusToFahrenheit & fahrenheitToCelsius

import Swift // or Foundation

extension Double {

    func celsiusToFahrenheit() -> Double {
        return self * 9 / 5 + 32
    }

    func fahrenheitToCelsius() -> Double {
        return (self - 32) * 5 / 9
    }
}
Example:
let boilingPointCelsius = 100.0
let boilingPointFarenheit = boilingPointCelsius.celsiusToFahrenheit()
print(boilingPointFarenheit) // 212.0

Description

Convert a (double) fahrenheit to (or from) celsius

Details

  • Author: Fons
  • Submitted on: 2/23/2017 2:14:56 PM
  • Language: Swift
  • Type: Double
  • Views: 138

Double click on the code to select all.

 

;