Zia
Zia

Reputation: 14722

Find decimal mark character based on locale

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.

Upvotes: 0

Views: 182

Answers (1)

rmaddy
rmaddy

Reputation: 318824

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.

Upvotes: 2

Related Questions