In most cases, the currency symbol will not be enough. For example, in Germany we write our prices as follows: 1.99 β¬, but people in the USA use 1.99 US dollars. There are three differences in the line. Currency symbol, its position and separator.
If you want to do this correctly, you must use NSNumberFormatter. He takes care of all the differences between currency formats. And it is much better than you. Because he does it for all currencies, and not just for the 4 major currencies that you want to support.
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [formatter setLocale:[NSLocale currentLocale]]; NSString *localizedMoneyString = [formatter stringFromNumber:myCurrencyNSNumberObject];
If you want to use this to buy an application, you cannot rely on the current locale of users, because you can use an account in the USA on a device with a German language standard. And the price of your product (actual price of 0.79 β¬ in Germany) will show as 0.99 β¬ (because it costs 0.99 US dollars). That would be wrong. You get the localized price already from the application store, you do not need to do the calculations yourself.
And you get a price and priceLocale for each of your SKProducts.
You will receive the correct formatted currency string as follows:
SKProduct *product = [self.products objectAtIndex:indexPath.row]; NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease]; [formatter setNumberStyle:NSNumberFormatterCurrencyStyle]; [formatter setLocale:product.priceLocale]; currencyString = [formatter stringFromNumber:product.price];
EDIT: since you specifically requested a currency code.
You can get it with NSString *currencyCode = [formatter currencyCode]; . This will give you a currency code according to ISO 4217. AUD, USD, EUR and so on.
Matthias Bauch Feb 18 '11 at 9:10 2011-02-18 09:10
source share