Skip to content
This repository has been archived by the owner on Mar 7, 2021. It is now read-only.

Show localized dots for float numbers (comas and dots) #54

Closed
3lvis opened this issue Oct 29, 2014 · 2 comments
Closed

Show localized dots for float numbers (comas and dots) #54

3lvis opened this issue Oct 29, 2014 · 2 comments

Comments

@3lvis
Copy link
Owner

3lvis commented Oct 29, 2014

If norwegian ,
If english .

@jeffleeismyhero
Copy link
Collaborator

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 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: $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 Norwegian

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: 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 tohundre­og­fire­og­tredve tusen og femhundre­og­syv­og­seksti 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

@aminiz
Copy link
Contributor

aminiz commented May 11, 2016

Is this also addressed by #521

@3lvis 3lvis closed this as completed May 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants