Convert Kelvin to Fahrenheit with Swift March 10, 2016

I finished my Weather App 'SexyWeather'! Check it out on the AppStore.

I used WeatherUnderground's API, and it returns temperatures in degrees Kelvin. I doubt you know if 300° kelvin is a boiling hot beach day or arctic freezing (nor does anybody else), so I had to convert these into Fahrenheit.

      func convertKelvinToFahrenheitAndRemoveDecimals(kelvin: String) -> String {

        let kelvinFloat = Float(kelvin)
        let fahrenheitFloat: Float = (kelvinFloat! - 273.15) * 9/5 + 32
        let roundedUpFahrenheitInt: Int = Int(ceilf(fahrenheitFloat))
        return String(roundedUpFahrenheitInt)


I also didn't need anything past the decimal for my app, so I rounded the values up to the nearest Int. You could remove the 'roundedUpFahrenheitInt' line and return the 'fahrenheitFloat' instead if you didn't need the rounding.

And in case you need to convert Kelvin to Celsius:

      func convertKelvinToCelsiusAndRemoveDecimals(kelvin: String) -> String {
        let kelvinFloat = Float(kelvin)
        let celsiusFloat: Float = kelvinFloat! - 273.15
        let roundedUpCelsiusInt: Int = Int(ceilf(celsiusFloat))
        return String(roundedUpCelsiusInt)

That's it! Have fun and #CompileSwift.