Comments (2)
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 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
from form.
Is this also addressed by #521
from form.
Related Issues (20)
- Feature Request: Consider adding standard UITextView field type HOT 1
- Feature Proposal: Show validation error message beside form field title HOT 9
- Feature Request: Allow custom input validator HOT 8
- How does one subscribe a custom cell's FORMBaseFieldDelegate to the conforming class FORMDataSource? HOT 1
- Use case difference between Sections and Fields HOT 5
- Dynamic Buttons HOT 3
- [Question] How does your GroupHeaders keep track of their collapsed state upon dequeue? HOT 8
- How to create form templates which creates JSON? HOT 11
- Do the Form support multiple checkboxes? HOT 5
- Add tests for Hidden field order #571
- How do I choose id for each element? HOT 1
- NSInternalInconsistency exception when attempting to process FORMTarget HOT 1
- Swift Syntax Error HOT 1
- FORMFieldValuesTableViewController navigation bar title color change
- Segment get unselected when combined with Show target HOT 2
- Show/Hide group HOT 7
- Memory leaks in demo project (and so in projects using the lib)
- Potential memory leaks in Model layer
- View transition bug when keyboard show, only in iOS 11 HOT 7
- Multiselect support HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from form.