Extension

extension String {

func toFloat() -> Float {

if let unwrappedNum = Float(self) {

return unwrappedNum

}

else {

print(“Error converting \”” + self + “\” to Float”)

return 0.0

}

}

}

// Double to String with Format

var text = String.localizedStringWithFormat(“%.2f”, doubleValue)

// String to Float/Double

var floatValue = text.toFloat()