Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created September 23, 2014 14:31
Show Gist options
  • Select an option

  • Save vikdenic/08c1c7f0b7d1ecc96c86 to your computer and use it in GitHub Desktop.

Select an option

Save vikdenic/08c1c7f0b7d1ecc96c86 to your computer and use it in GitHub Desktop.
extension String
{
///:returns: The floating-point value of the string as a double.
func toDouble() -> Double
{
let convertedString = self as NSString
return convertedString.doubleValue
}
///:returns: The NSInteger value of the string.
func toInteger()-> Int
{
let convertedString = self as NSString
return convertedString.integerValue
}
}
extension Double
{
///:returns: The the US Dollars representation of the double rounded to the nearest hundreth, as a String (i.e. $7.45)
func toCurrency() ->String
{
let convertedString = NSString(format: "$%.2f", self)
return convertedString
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment