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: 23-2-2017 14:14:56
  • Language: Swift
  • Type: Double
  • Views: 1164

Double click on the code to select all.

 

;