Reputation: 27159
How to show . instead of , symbol for decimal pad?
I found a few solution with using NSNumberFormatter, replacing string on the fly and extension of UIEnglishTextField
, which should return localised textfield.
No of these solutions worked for me.
I mean for sure I can transform string, but is there a way to display right dot symbol.
Upvotes: 2
Views: 1391
Reputation: 27159
It's out of topic, but this code works for me (SWIFT 5):
extension String {
static let numberFormatter = NumberFormatter()
var doubleValue: Double? {
String.numberFormatter.decimalSeparator = "."
if let result = String.numberFormatter.number(from: self) {
return result.doubleValue
} else {
String.numberFormatter.decimalSeparator = ","
if let result = String.numberFormatter.number(from: self) {
return result.doubleValue
} else {
return nil
}
}
}
}
Upvotes: 1