ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

celsiusToFahrenheit & fahrenheitToCelsius

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

Source

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

Author: Fons

Submitted on: 23 feb 2017

Language: Swift

Type: Double

Views: 2363