Created
May 22, 2014 19:21
-
-
Save diederikh/0c2c7247b57359389637 to your computer and use it in GitHub Desktop.
Format currency into a string using locale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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