Created
          June 23, 2015 11:02 
        
      - 
      
- 
        Save dedeexe/bee58e7e9894b92a42e9 to your computer and use it in GitHub Desktop. 
    Converting String to Float and Double
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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