iOS  Tree

"All of us do not have equal talent. But , all of us have an equal opportunity to develop our talents.” – A.P.J Abdul Kalam

Convert String to Float Swift — June 28, 2018

Convert String to Float Swift

You can use Optional Float, stick a ! at the end if you know it to be a Float, or use if/let

let floatConversion = Float("5.6")

The best way to handle this is direct casting:

extension String {
var floatValue: Float {
return (self as NSString).floatValue
}
}

Now you can just call

var floatConversion = "5.6".floatValue