The decimal mark can be a dot or comma based on the locale. How can I determine which one it is?
I have read through the docs on Formatting Data Using the Locale Settings but cannot figure out how do this.
There are two ways. Get the NSLocaleDecimalSeparator
attribute from NSLocale
or use the decimalSeparator
property from NSNumberFormatter
.
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSString *separator = [formatter decimalSeparator];
or:
NSLocale *locale = [NSLocale currentLocale];
NSString *separator = [locale objectForKey:NSLocaleDecimalSeparator];
Both of these examples assume you want to work with the user's default locale.