I want to format a number like 1,000,000,000 instead of 1000000000 in CS193P calculator based my version of calculator app. I did some research about similar question and other CS193P based calculators. Then I found answers that could be an answer of my question like these article.
- How to add commas to numbers? (MacRumors Forums)
https://forums.macrumors.com/threads/916491/
- NSNumberFormatter IOS Calculator display (Stack Overflow)
http://stackoverflow.com/questions/18025635/nsnumberformatter-ios-calculator-display
- NSNumberFormatter Class Reference (iOS Developer Library)
https://developer.apple.com/library...umberFormatter_Class/Reference/Reference.html
- NumberFormatters Data Formatting Guid (iOS Developer Library)
https://developer.apple.com/library...rmatting/Articles/dfNumberFormatting10_4.html
But problem is I don't know how it convert into my code.
Please give me an example or correct my code would be really appreciate.
How to formatting a number with thousands separator?
How to set limitation to display like display able to show up to 10 digits of number including floating point?
For example some number like 1,000.123456789, I want to show that number like 1,000.123457 instead of 1,000.123456789 or 1,000.123456 based on condition something like round up if the number is bigger than 10 digit including floating numbers.
My code is
- How to add commas to numbers? (MacRumors Forums)
https://forums.macrumors.com/threads/916491/
- NSNumberFormatter IOS Calculator display (Stack Overflow)
http://stackoverflow.com/questions/18025635/nsnumberformatter-ios-calculator-display
- NSNumberFormatter Class Reference (iOS Developer Library)
https://developer.apple.com/library...umberFormatter_Class/Reference/Reference.html
- NumberFormatters Data Formatting Guid (iOS Developer Library)
https://developer.apple.com/library...rmatting/Articles/dfNumberFormatting10_4.html
But problem is I don't know how it convert into my code.
Please give me an example or correct my code would be really appreciate.
How to formatting a number with thousands separator?
How to set limitation to display like display able to show up to 10 digits of number including floating point?
For example some number like 1,000.123456789, I want to show that number like 1,000.123457 instead of 1,000.123456789 or 1,000.123456 based on condition something like round up if the number is bigger than 10 digit including floating numbers.
My code is
Code:
- (IBAction)digitPressed:(UIButton *)sender {
error.text = nil;
NSString *digit = [[sender titleLabel] text];
if (userIsInTheMiddleOfTypingANumber) {
[display setText:[[display text] stringByAppendingString:digit]];
} else {
[display setText:digit];
userIsInTheMiddleOfTypingANumber = YES;
}
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setPositiveFormat:@",###"];
}