Skip to content

Instantly share code, notes, and snippets.

@dedeexe
Created June 23, 2015 11:02
Show Gist options
  • Save dedeexe/bee58e7e9894b92a42e9 to your computer and use it in GitHub Desktop.
Save dedeexe/bee58e7e9894b92a42e9 to your computer and use it in GitHub Desktop.
Converting String to Float and Double
import Foundation
extension String {
func toFloat() -> Float
{
return (self as NSString).floatValue
}
func toDouble() -> Double
{
return (self as NSString).doubleValue
}
}
//
//Usage
//
var strNumber : String = "6.9"
var floatNumber = strNumber.toFloat()
var doubleNumber = strNumber.toDouble()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment