Reputation: 38162
I want to localize the price in my iPhone app. Can you please guide me how to achieve this.
For example:
$50 Vs A$ 1,480.00 Vs RMB 1450 Vs £999.00 etc.
Upvotes: 0
Views: 143
Reputation: 243156
You have two problems:
The second one is fairly simple, and @coneybeare answered it in his post: use an NSNumberFormatter
.
The first part is also fairly simple, if you know where to look. I recommend checking out a unit converter library I wrote called DDUnitConverter: https://github.com/davedelong/DDUnitConverter
One of the conversion modules it has is a currency converter, which asynchronously pulls it's rates from the International Monetary Fund.
Upvotes: 2
Reputation: 33101
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:[NSLocale currentLocale]];
NSString *formattedString = [numberFormatter stringFromNumber:price];
NSLog(@"Local price: %@", formattedString);
if you just want the currency symbol, you can use:
NSString *sym = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencySymbol]
Upvotes: 4