tdjfdjdj
tdjfdjdj

Reputation: 2471

How to determine if locale currency has a decimal point

Is there anyway in objective-c to determine if a currency uses a decimal point (regardless of declared NSNumber type)?

I have multiple locales and I use NSNumberFormatter (based on locale) to set string currency string style, however before-hand I would like to know if the selected locale currency uses a decimal point.

[_cf setLocale:
[NSLocale localeWithLocaleIndentifier:[NSString stringWithFormat:@"%@",locale]]]];
[cf setNumberStyle:NSNUmberFormatterCurrencyStyle];
NSString *value = [cf stringFromNumber:price];
return value;

Upvotes: 0

Views: 406

Answers (1)

rmaddy
rmaddy

Reputation: 318884

After creating the NSNumberFormatter with currency style, ask the formatter how many fraction digits it has.

NSInteger maxFractionDigits = cf.maximumFractionDigits;
if (maxFractionDigits == 0) {
    // this currency is an integer, not a decimal
}

One example where this is true is the Japanese Yen (¥).

Upvotes: 3

Related Questions