I want to swing back to a point that QuinceyMorris made right at the start of this thread:
The decimal point character is locale-specific.
It’s not just the decimal point that’s a concern here, it’s the digits themselves. For example:
let digits = CharacterSet.decimalDigits
let d = UnicodeScalar(0x0661)! // U+0661 ARABIC-INDIC DIGIT ONE
print(digits.contains(d)) // prints "true"
So, either you want to support internationalisation or you don’t. If you do, you really need to look at
NumberFormatter
because any other approach is fraught with much danger. If you don’t — and there are plenty of contexts where it’s safe to ignore internationalisation — you should eschew
decimalDigits
and just build a digits set from the ASCII 0 through 9.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"