views:

458

answers:

3

On the iPhone:

Using the US locale, a currency looks like this: $1,234.56
Using the UK locale, a currency looks like this: £1,234.56
Using the German (Germany) locale, a currency looks like this: 1.234,56 €

and finally, a Japanese currency: ¥1,234

The Japanese currency has no decimals and this impacts my custom keyboard significantly. I'm trying to find a method in the Cocoa-touch framework which will tell me how many decimal places a specific currency has - my hard-coded value of 2 isn't doing me justice :(

Can anyone help?

A: 

Financial companies maintain databases of this kind of information. You might be able to buy the data or import it from an online source.

Note also: some currencies need three or four decimal places. See http://www.londonfx.co.uk/ccylist.html for examples.

Nat
The NSNumberFormatter is brilliant for this. I don't have a problem with formatting since it's all done for me by the formatter. I just can't find out how to determine how many decimal places I need to provision for. Thanks for the link - interesting stuff.
rein
By the way, ideally, I'd like to tie the number of decimals with whatever is coded into the formatter - otherwise things could just go wrong.
rein
+2  A: 

I haven't programmed in Cocoa for ages, but from the documentation for NSNumberFormatter, there's a function called 'currencyDecimalSeparator' - that might at least tell you if a currency has one at all, which might be a start?

Steve Mc
+2  A: 

You should be able to use the CFNumberFormatter objects to get the information you need. Specifically you could use CFNumberFormatterGetDecimalInfoForCurrencyCode:

CFStringRef localeIdent = CFSTR("JPY");

int numDecimals;
double rounding;
BOOL result = CFNumberFormatterGetDecimalInfoForCurrencyCode(localeIdent, &numDecimals, &rounding);

I hope that helps.

RichardCase