Skip to content

Instantly share code, notes, and snippets.

@diederikh
Created May 22, 2014 19:21
Show Gist options
  • Save diederikh/0c2c7247b57359389637 to your computer and use it in GitHub Desktop.
Save diederikh/0c2c7247b57359389637 to your computer and use it in GitHub Desktop.
Format currency into a string using locale
NSDecimalNumber *price = [NSDecimalNumber decimalNumberWithString:@"1.99"];
NSLocale *priceLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"be_BE"] autorelease]; // get the locale from your SKProduct
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setLocale:priceLocale];
NSString *currencyString = [currencyFormatter currencySymbol];
NSString *format = [currencyFormatter positiveFormat];
format = [format stringByReplacingOccurrencesOfString:@"¤" withString:currencyString];
// ¤ is a placeholder for the currency symbol
[currencyFormatter setPositiveFormat:format];
NSString *formattedCurrency = [currencyFormatter stringFromNumber:price];
NSLog(@"price:%@", formattedCurrency);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment