Search code examples
iosobjective-cnsnumberformatter

Change Dollars with NSNumberFormatter


in Itunes $0.99 == Rp9500

I want to show like these:

for US region: $0.99 and for Indonesia region Rp9500

how to convert USD to IDR?

here is my code.

NSNumberFormatter *priceFormatter = [[NSNumberFormatter alloc] init];
[priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[priceFormatter setLocale:[NSLocale currentLocale]];
[_priceFormatter stringFromNumber:@(0.99)]

the result from code above are:

for US region $0.99

and

for Indonesia region Rp 1 (I don't understand, why it is become 1 and not 9500)

thank you very much, I'm sorry for my bad English


Solution

  • NSNumberFormetter does exactly what it's name implies - given a number it formats (produces a textual representation of it). The class does not convert numbers between different units, two currencies in your case. To do the conversion you need to look up the conversion rate and do the multiplication yourself.