Skip to content

Instantly share code, notes, and snippets.

@tonycn
Last active June 23, 2016 09:59
Show Gist options
  • Save tonycn/664399a01c653120a581f6e23478eeb7 to your computer and use it in GitHub Desktop.
Save tonycn/664399a01c653120a581f6e23478eeb7 to your computer and use it in GitHub Desktop.
currency NSLocale
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setLocale:[NSLocale currentLocale]];
NSLog(formatter.currencyCode);
NSLog([formatter stringFromNumber:@100]);
formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
// [formatter setLocale:[NSLocale currentLocale]];
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]];
[formatter stringFromNumber:@100];
NSLog(formatter.currencyCode);
NSLog([formatter stringFromNumber:@100]);
formatter = [[NSNumberFormatter alloc] init];
[formatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
// [formatter setLocale:[NSLocale currentLocale]];
[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"ja_JP"]];
[formatter stringFromNumber:@100];
NSLog(formatter.currencyCode);
NSLog([formatter stringFromNumber:@100]);
NSNumberFormatter *formatter;
NSLocale *locale = nil;
NSString *str;
formatter = [[NSNumberFormatter alloc] init];
locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
[formatter setLocale:locale];
str = [NSString stringWithFormat:@"%@%@", formatter.currencySymbol, @100];
NSLog(str);
formatter = [[NSNumberFormatter alloc] init];
locale = [NSLocale localeWithLocaleIdentifier:@"ja_JP"];
[formatter setLocale:locale];
str = [NSString stringWithFormat:@"%@%@", formatter.currencySymbol, @120];
NSLog(str);
formatter = [[NSNumberFormatter alloc] init];
locale = [NSLocale localeWithLocaleIdentifier:@"en_US"];
[formatter setLocale:locale];
str = [NSString stringWithFormat:@"%@%@", formatter.currencySymbol, @140];
NSLog(str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment