Skip to content

Instantly share code, notes, and snippets.

@adriantofan
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriantofan/6f91841d8f6594f2f364 to your computer and use it in GitHub Desktop.
Save adriantofan/6f91841d8f6594f2f364 to your computer and use it in GitHub Desktop.
NSLocale *locale = [NSLocale currentLocale];
// [locale localeIdentifier] fr_FR (i'm in france)
NSLog(@"current locale: %@", locale.localeIdentifier);
NSArray* preferredLanguages = [NSLocale preferredLanguages];
NSLog(@"preferredLanguages: %@", preferredLanguages);
// en,fr ( the interface is in english )
NSString* code = [locale objectForKey:NSLocaleCurrencyCode];
NSLog(@"NSLocaleCurrencyCode: %@", code);
// EUR (based onlocaleIdentifier)
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setLocale:[NSLocale currentLocale]];
[currencyFormatter setMaximumFractionDigits:2];
[currencyFormatter setMinimumFractionDigits:2];
[currencyFormatter setAlwaysShowsDecimalSeparator:YES];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSNumber *someAmount = [NSNumber numberWithFloat:5.00];
NSString *stringAmount = [currencyFormatter stringFromNumber:someAmount];
NSLog(@"%@",stringAmount);
// 5,00 €
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment