I have a string, "$4,102.33"
that needs to be converted to double. This will always be US. My only way is a hack to strip out the $
and ,
and then convert to double. Seems like NSFormatter
only lets me convert TO a currency and not from it. Is there a built-in function or better way than just removing the $
and ,
? prior to converting it to double?
相关问题
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Get the NSRange for the visible text after scroll
- UIPanGestureRecognizer is not working in iOS 13
- What does a Firebase observer actually do?
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
To convert from String to NSNumber for a given currency is easy:
To get your number as a Double or as a Decimal (preferred) is then direct:
NumberFormatter
can convert to and from string. AlsoDouble
cannot represent certain numbers exactly since it's based 2. UsingDecimal
is slower but safer.