This repository has been archived by the owner on Mar 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 145
Show localized dots for float numbers (comas and dots) #54
Comments
It seems that this could be an implementation option that applies to all fields OR as a per-field option. I propose that the option live in the JSON file(s) to allow quick and easy changes based on a user's locale or the context in an application. I'm not familiar with how iOS handles different locales or if it is a viable option for this project. This seems to be a well written resource on the matter: http://useyourloaf.com/blog/2012/06/14/using-number-formatters.html Example: Device language set as EnglishNSNumber *number = [NSNumber numberWithDouble:1234567.8369];
NSString *numberString = @"";
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterNoStyle];
NSLog(@"NSNumberFormatterNoStyle: %@", numberString);
// => NSNumberFormatterNoStyle: 1234568
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterDecimalStyle];
NSLog(@"NSNumberFormatterDecimalStyle: %@", numberString);
// => NSNumberFormatterDecimalStyle: 1,234,567.837
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyStyle];
NSLog(@"NSNumberFormatterCurrencyStyle: %@", numberString);
// => NSNumberFormatterCurrencyStyle: $1,234,567.84
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterPercentStyle];
NSLog(@"NSNumberFormatterPercentStyle: %@", numberString);
// => NSNumberFormatterPercentStyle: 123,456,784%
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterScientificStyle];
NSLog(@"NSNumberFormatterScientificStyle: %@", numberString);
// => NSNumberFormatterScientificStyle: 1.2345678369E6
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterSpellOutStyle];
NSLog(@"NSNumberFormatterSpellOutStyle: %@", numberString);
// => NSNumberFormatterSpellOutStyle: one million two hundred thirty-four thousand five hundred sixty-seven point eight three six nine Example: Device language set as NorwegianNSNumber *number = [NSNumber numberWithDouble:1234567.8369];
NSString *numberString = @"";
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterNoStyle];
NSLog(@"NSNumberFormatterNoStyle: %@", numberString);
// => NSNumberFormatterNoStyle: 1234568
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterDecimalStyle];
NSLog(@"NSNumberFormatterDecimalStyle: %@", numberString);
// => NSNumberFormatterDecimalStyle: 1 234 567,837
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyStyle];
NSLog(@"NSNumberFormatterCurrencyStyle: %@", numberString);
// => NSNumberFormatterCurrencyStyle: USD 1 234 567,84
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterPercentStyle];
NSLog(@"NSNumberFormatterPercentStyle: %@", numberString);
// => NSNumberFormatterPercentStyle: 123 456 784 %
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterScientificStyle];
NSLog(@"NSNumberFormatterScientificStyle: %@", numberString);
// => NSNumberFormatterScientificStyle: 1,2345678369E6
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterSpellOutStyle];
NSLog(@"NSNumberFormatterSpellOutStyle: %@", numberString);
// => NSNumberFormatterSpellOutStyle: én million tohundreogfireogtredve tusen og femhundreogsyvogseksti komma åtte tre seks ni Example: Device region set as Norway (language English)NSNumber *number = [NSNumber numberWithDouble:1234567.8369];
NSString *numberString = @"";
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterNoStyle];
NSLog(@"NSNumberFormatterNoStyle: %@", numberString);
// => NSNumberFormatterNoStyle: 1234568
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterDecimalStyle];
NSLog(@"NSNumberFormatterDecimalStyle: %@", numberString);
// => NSNumberFormatterDecimalStyle: 1 234 567,837
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterCurrencyStyle];
NSLog(@"NSNumberFormatterCurrencyStyle: %@", numberString);
// => NSNumberFormatterCurrencyStyle: NOK 1 234 567,84
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterPercentStyle];
NSLog(@"NSNumberFormatterPercentStyle: %@", numberString);
// => NSNumberFormatterPercentStyle: 123 456 784%
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterScientificStyle];
NSLog(@"NSNumberFormatterScientificStyle: %@", numberString);
// => NSNumberFormatterScientificStyle: 1,2345678369E6
numberString = [NSNumberFormatter localizedStringFromNumber:number numberStyle:NSNumberFormatterSpellOutStyle];
NSLog(@"NSNumberFormatterSpellOutStyle: %@", numberString);
// => NSNumberFormatterSpellOutStyle: one million two hundred thirty-four thousand five hundred sixty-seven point eight three six nine Alternatively, you could set the region at the app level by creating and implementing custom formatters. This may provide an easy way to change the grouping and decimal separators on demand. Example: Custom formatter// Custom formatter
NSNumber *number = [NSNumber numberWithDouble:1234567.8369];
NSString *numberString = @"";
NSNumberFormatter *customFormatter = [[NSNumberFormatter alloc] init];
[customFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[customFormatter setGroupingSeparator:@" "];
[customFormatter setDecimalSeparator:@","];
numberString = [customFormatter stringFromNumber:number];
NSLog(@"NSNumberFormatterDecimalStyle (custom formatter): %@", numberString);
// => NSNumberFormatterDecimalStyle (custom formatter): 1 234 567,837 |
Is this also addressed by #521 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
If norwegian
,
If english
.
The text was updated successfully, but these errors were encountered: