Im trying to do the calculations using NSNumbers and keep track of the numbers that the user inputs..
The problem is that my app is not doing any calculations now after updated my code to append . the decimal value to value whenever the user press the dot button. Which can be found Append or Add the decimal point functionality in calculator.
I have seen that the proper way to keep track of the inputs from the user and do the calculation is using the NSNumber but as I'm really new to Objective-c I have been struggling understanding the use and implementing it.
So, hopefully someone could walk me through to find the proper solution.
This is the header...
int Method;
float SelectNumber;
float RunningTotal;
bool DecimalActived;
#interface ViewController : UIViewController{
IBOutlet UILabel *Screen;
}
-(IBAction)Number9:(UIButton *)sender;
-(IBAction)Dot:(UIButton *)sender;
#end
This is the the implementation file..
-(IBAction)Number9:(UIButton *)sender{
[self appendDigit:#"9"];
}
- (IBAction)Dot:(UIButton *)sender {
NSString *currentText = Screen.text;
if ([currentText rangeOfString:#"." options:NSBackwardsSearch].length == 0) {
[self appendDigit:#"."];
}
}
- (void)appendDigit:(NSString *)digit {
// handle two special cases: append to only zero means just replace
// but append decimal point to zero is a regular append
if ([self->Screen.text isEqualToString:#"0"] && ![digit isEqual:#"."]) {
self->Screen.text = digit;
} else {
self->Screen.text = [Screen.text stringByAppendingString:digit];
}
}
- (IBAction)Percent:(UIButton *)sender {
[self MySwitch];
Method = 5;
SelectNumber = 0;
DecimalActived = FALSE;
Screen.text = [NSString stringWithFormat:#"%.2g", RunningTotal];
}
- (IBAction)PositiveOrNegative:(UIButton *)sender {
[self MySwitch];
Method = 6;
SelectNumber = 0;
DecimalActived = FALSE;
Screen.text = [NSString stringWithFormat:#"%g", RunningTotal];
}
-(IBAction)Equals:(UIButton *)sender{
[self MySwitch];
Method = 0;
SelectNumber = 0;
DecimalActived = FALSE;
Screen.text = [NSString stringWithFormat:#"%g", RunningTotal];
}
-(IBAction)AllClear:(UIButton *)sender{
Method = 0;
RunningTotal = 0;
SelectNumber = 0;
Screen.text = [NSString stringWithFormat:#"0"];
}
- (double) MySwitch {
NSNumberFormatter SelectNumber = [[NSNumberFormatter alloc] init];
[SelectNumber setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber RunningTotal = [SelectNumber numberFromString:self->Screen.text];
if (RunningTotal == 0) {
RunningTotal = SelectNumber;
} else{
switch (Method) {
case 1:
RunningTotal = RunningTotal * SelectNumber;
break;
case 2:
RunningTotal = RunningTotal / SelectNumber;
break;
case 3:
RunningTotal = RunningTotal - SelectNumber;
break;
case 4:
RunningTotal = RunningTotal + SelectNumber;
break;
case 5:
RunningTotal = RunningTotal / 100;
break;
case 6:
if(RunningTotal > 0){
RunningTotal = - RunningTotal;
} else{
RunningTotal = + RunningTotal;
}
break;
default:
break;
}
}
return RunningTotal;
}
If you guys have any question or need more information regarding my program please feel free to ask and I will provide as much information as possible or answer any questions that you guys may have.. :)
The header should look more like this:
// this uses more conventional (lowercase) property names
// and removes a couple that looked extraneous
#interface ViewController : UIViewController
#property(strong,nonatomic) IBOutlet UILabel *screen;
#property(assign,nonatomic) NSInteger method;
#property(strong,nonatomic) NSNumber *runningTotal;
#end
As the user presses digits, decimal, minus sign, append to the screen label as you have it. When the user presses an operation button, record an integer for the operation and record the current (NSNumber) value of the screen label. To do a computation...
- (void)doComputation {
float screenF = [[self screenValue] floatValue];
float runningF = [self.runningTotal floatValue];
float result;
switch (self.method) {
case 1:
result = runningF * screenF;
break;
case 2:
result = (screenF == 0.0)? 0.0 : runningF / screenF;
break;
case 3:
result = runningF - screenF;
break;
case 4:
result = runningF + screenF;
break;
default:
break;
}
self.screen.text = [NSString stringWithFormat:#"%0.8f", result];
self.runningTotal = [NSNumber numberWithFloat:result];
}
(screen value, as you have it...)
- (NSNumber *)screenValue {
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
return [f numberFromString:self.screen.text];
}
How does this work?
NSNumberFormatter SelectNumber = [[NSNumberFormatter alloc] init];
[SelectNumber setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber RunningTotal = [SelectNumber numberFromString:self->Screen.text];
if (RunningTotal == 0) {
RunningTotal = SelectNumber;
} else{
switch (Method) {
case 1:
RunningTotal = RunningTotal * SelectNumber;
break;
This code shouldn't even work. Either SelectNumber is a float or it's a NSNumberFormatter*
Related
I make a quiz game.I put a label for question in the screen.When I was trying to change it's text the text didn't change.
QuizScreen.h
#import <UIKit/UIKit.h>
int score = 0;
int lives = 3;
int QuestionSelected = 0;
NSString *AnswerRunning;
#interface QuizScreen : UIViewController
{
IBOutlet UITextField *Answer;
IBOutlet UIButton *Go;
IBOutlet UILabel *Question;
IBOutlet UILabel *Session;
IBOutlet UILabel *Lives;
IBOutlet UILabel *Score;
IBOutlet UIButton *Exit;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(IBAction)GoBtn:(id)sender;
-(void)questioning;
#end
QuizScreen.m
#import "QuizScreen.h"
#interface QuizScreen ()
#end
#implementation QuizScreen
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
-(IBAction)GoBtn:(id)sender{
switch (QuestionSelected) {
case 0:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 1:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 2:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 3:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 4:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 5:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 6:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
QuestionSelected = QuestionSelected + 1;
break;
case 7:
if ([Answer.text isEqualToString: #"YOUR WORD"]){
score = score + 1;
Score.text = [NSString stringWithFormat:#"Score: %i" , score];
Session.text = [NSString stringWithFormat:#"Correct Answer!! Score +1"];
}else{
lives = lives - 1;
Lives.text = [NSString stringWithFormat:#"Lives: %i" , lives];
Session.text = [NSString stringWithFormat:#"Wrong Answer!!! Lives -1"];
}
break;
default:
break;
}
}
-(void)questioning {
switch (QuestionSelected) {
case 0:
Question.text = #"You can only keep it once you give it to somebody.What is it?";
break;
case 1:
Question.text = #"Light hides me and darkness kills me.What am I?";
break;
case 2:
Question.text = #"Voiceless it cries,Wingless flutters,Toothless bites,Mouthless mutters.";
break;
case 3:
Question.text = #"What goes in the water black and comes out red?";
break;
case 4:
Question.text = #"It's hard to give up.Remove part of it and you still have a bit.Remove another part, but bit is still there.Remove another and it remains.What is it?";
break;
case 5:
Question.text = #"With pointed fangs I sit and wait,with piercing force I serve out fate.Grabbing bloodless victims, proclaiming my might;physically joining with a single bite.What am I?";
break;
case 6:
Question.text = #"Jasmine has a toaster with two slots that toasts one side of each piece of bread at a time, and it takes one minute to do so.If she wants to make 3 pieces of toast, what is the least amount of time she needs to toast them on both sides?";
break;
case 7:
Question.text = #"A man was born on January 1st, 23 B.C. and died January 2nd, 23 A.D. How old did he live to be?";
break;
default:
break;
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
When I run it and write the answer the label's text doesn't change.I tried stringWithFormat but it doesn't work.The strange part is the session label's text changes.But I couldn't find any differences
It seems that Question label's text changes only in method:
-(void)questioning;
But I can't find where you are calling one. Set breakpoint on entrance of it, mb you are never getting there. As I understood your code [self questioning] should be called in viewDidLoad and at the end of GoBtn: methods.
P.S.
You should pay attention to the Coding Guidelines for Cocoa, General Coding Standards and Conventions. Especially to the naming variables, data types, methods e.t.c. (E.g. variables shouldn't start with capital letter, Class or structures should)
I am new to creating apps for the iOS. Recently, I've been working on making a calculator app based on gestures. I am using switch cases to change operations, and I originally had it rigged up with buttons, but now I want to use gestures. Here is my code so far. The opAddition function is the first way I tried it, but it wouldn't switch functions. For example, if I wanted to switch from addition to subtraction, it would only work after the number was inputed. That's why I tried to use Switch-Case, but now I don't know how to link up gestures to them.
#implementation ABViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
calculatorScreen.adjustsFontSizeToFitWidth = YES;
self.notification.layer.cornerRadius = 90;
self.notification.layer.masksToBounds = YES;
self.notification.alpha = 0;
[[self.notification layer] setBorderWidth:8.0f];
[[self.notification layer] setBorderColor:[UIColor whiteColor].CGColor];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - buttons
-(IBAction)buttonDigitPressed:(id)sender{
currentNumber = currentNumber *10 + (int)[sender tag];
NSString *number = [NSString stringWithFormat:#"%.1f", currentNumber];
if ( number.length < 11) {
calculatorScreen.text = number;
}
};
#pragma mark - operator button code
-(IBAction)buttonOperationPressed:(id)sender{
if (currentOperation == 0) { result = currentOperation; }
else {
if (_operationSimple.direction == UISwipeGestureRecognizerDirectionUp){
currentOperation = 1;
} else if (_operationSimple.direction == UISwipeGestureRecognizerDirectionDown){
currentOperation = 2;
}
switch (currentOperation) {
case 1:
result = result + currentNumber;
self.notificationText.text = #"+";
[self notify];
break;
case 2:
result = result - currentNumber;
self.notificationText.text = #"-";
[self notify];
break;
case 3:
result = result * currentNumber;
break;
case 4:
result = result / currentNumber;
break;
case 5:
currentOperation = 0;
break;
}
}
currentNumber = 0;
calculatorScreen.text = [NSString stringWithFormat:#"%.1f", result];
if ( [sender tag] == 0) { result = 0; }
currentNumber = [sender tag];
};
#pragma mark - Cancelations
-(IBAction)cancelInput{
currentNumber = 0;
self.notificationText.text = #"C";
[self notify];
calculatorScreen.text = #"0.0";
result = 0.0;
NSLog(#"Cancel Input");
}
-(IBAction)cancelOperation{
currentNumber = 0;
self.notificationText.text = #"AC";
[self notify];
calculatorScreen.text = #"0.0";
currentOperation = 0;
NSLog(#"Clear Operation");
}
double newresult = 0;
#pragma mark - Operations
-(IBAction)opAddition{
result = result + currentNumber;
self.notificationText.text = #"+";
[self notify];
newresult = result;
currentNumber = 0;
NSLog(#"Number Added. New result:");
NSLog([NSString stringWithFormat:#"%2f", newresult]);
calculatorScreen.text = [NSString stringWithFormat:#"%.1f", result];
}
#pragma mark - notification stuffs
- (void)notify{
[UIView animateWithDuration:1.0 animations:^{
self.notification.alpha = 1.0f;
}];
[UIView animateWithDuration:1.0 animations:^{
self.notification.alpha = 0.0f;
}];
}
#end
I created a simple calculator. Everything works great; however, if I divide by zero, I would like to show an error message. I know how to do alert popups, but I don't know how to implement it so it comes up when I divide by zero. Here is a snipped of my calculator code:
- (IBAction)buttonOperationPressed:(id)sender {
if (currentOperation == 0) result = currentNumber;
else {
switch (currentOperation) {
case 1:
result = result + currentNumber;
break;
case 2:
result = result - currentNumber;
break;
case 3:
result = result * currentNumber;
break;
case 4:
result = result / currentNumber;
break;
case 5:
currentOperation = 0;
break;
default:
break;
}
}
currentNumber = 0;
CalcDisplay.text = [NSString stringWithFormat:#"%g",result];
if ([sender tag] == 0) result = 0;
currentOperation = [sender tag];
userInTheMiddleOfEnteringDecimal = NO;
You can just add a test prior to doing the division e.g. change:
case 4:
result = result / currentNumber;
break;
to:
case 4:
if (currentNumber == 0)
// ... do alert here ...
else
result = result / currentNumber;
break;
You have to check if the second division operand is zero, and if yes, then print an error message. Don't forget, that you can't just compare double or something with ==, you have to use presicion, like this:
case 4:
if(ABS(currentNumber) < 1e-12) // most probably its zero
// your message
return;
- (IBAction)buttonOperationPressed:(id)sender {
if (currentOperation == 0) result = currentNumber;
else {
switch (currentOperation) {
case 1:
result = result + currentNumber;
break;
case 2:
result = result - currentNumber;
break;
case 3:
result = result * currentNumber;
break;
case 4:
if(currentNumber == 0){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}else{
result = result / currentNumber;
}
break;
case 5:
currentOperation = 0;
break;
default:
break;
}
}
currentNumber = 0;
CalcDisplay.text = [NSString stringWithFormat:#"%g",result];
if ([sender tag] == 0) result = 0;
currentOperation = [sender tag];
userInTheMiddleOfEnteringDecimal = NO;
Please try this code, I have copied an pasted the code you have given and added some necessary lines to it which i felt would solve your issue.
Okay, so I'm creating X number of a custom UIView, that I've created in IB...
I create them in a grid-like formation and need to set their individual properties based on a response from a web service call...
The part I'm having trouble with is how to iterate through the different UIViews and set the variables...
I'm pretty sure the solution is really simple, but I've been staring blindly at this for some time now...
It's the part after:
if([theStatus.groupName isEqualToString:groupEntry.groupNameLabel.text])
{
Here is the entire method:
- (void)receivedGroups
{
int rows, columns;
if([groupConnection.groupsArray count] <= 4)
{
rows = 1;
columns = [groupConnection.groupsArray count];
} else if([groupConnection.groupsArray count] >= 5 && [groupConnection.groupsArray count] <= 8)
{
rows = 2;
columns = ([groupConnection.groupsArray count] + 1 )/ 2;
} else
{
rows = 3;
columns = ([groupConnection.groupsArray count] + 2 )/ 3;
}
int number = 0;
for(int j=1; j < columns+1; j++)
{
for(int k=0; k < rows; k++)
{
// Only create the number of groups that match the number of entries in our array
if(number < [groupConnection.groupsArray count])
{
// Create an instance of the group view
GroupEntry *groupEntry = [[GroupEntry alloc] initWithFrame:CGRectMake(230*j, 250*k, 180, 233)];
// Add it to the view
[self.view addSubview:groupEntry];
// Get the group
GetGroupsActive *theGroups = [groupConnection.groupsArray objectAtIndex:number];
groupEntry.groupNameLabel.text = theGroups.groupName;
for(int i=0; i<[statusConnection.statusArray count]; i++)
{
CurrentStatus *theStatus = [statusConnection.statusArray objectAtIndex:i];
if([theStatus.groupName isEqualToString:groupEntry.groupNameLabel.text])
{
//allChildren++;
switch(theStatus.currentStatus)
{
case 0:
//childrenSick++;
break;
case 1:
//childrenVacation++;
break;
case 2:
//childrenPresent++;
break;
case 3:
//childrenOut++;
break;
case 4:
//childrenTour++;
break;
default:
break;
}
}
}
NSString *allLabelText = [NSString stringWithFormat:#"%i", allChildren];
NSString *sickLabelText = [NSString stringWithFormat:#"%i", childrenSick];
NSString *vacationLabelText = [NSString stringWithFormat:#"%i", childrenVacation];
NSString *presentLabelText = [NSString stringWithFormat:#"%i", childrenPresent];
NSString *outLabelText = [NSString stringWithFormat:#"%i", childrenOut];
NSString *tripLabelText = [NSString stringWithFormat:#"%i", childrenTour];
groupEntry.sickLabelNumber.text = sickLabelText;
groupEntry.presentLabelNumber.text = presentLabelText;
groupEntry.numberLabelNumber.text = allLabelText;
groupEntry.tripLabelNumber.text = tripLabelText;
groupEntry.outLabelNumber.text = outLabelText;
groupEntry.vacationLabelNumber.text = vacationLabelText;
// Create the buttons to handle button press
UIButton *childButton = [UIButton buttonWithType:UIButtonTypeCustom];
childButton.frame = CGRectMake(230*j, 250*k, 180, 233);
// Set an identity tag, so we can recognize it during button press
childButton.tag = theGroups.ID;
// When EventTouchUpInside, send an action to groupSelected:
[childButton addTarget:self action:#selector(groupSelected:) forControlEvents:UIControlEventTouchUpInside];
// Add it to the view
[self.view addSubview:childButton];
}
number++;
}
}
}
If you added all the views in a parent view. You can get all the subviews using,
NSAarry *subviews = [base subviews];
for(UIView *subview in subviews)
{
subview.property = yourVaule;
}
You can differentiate between subviews using its tag or another property.
I have a simple calculator app and I want it to be so that if the answer requires no decimal places, there are none, just whole numbers. If the answer was 2, I don't want it to say 2.000000, it should say 2. If it requires one decimal place, it should show to one decimal place for example 12.8 instead of 12.80. How would I do this? Here is my code.
btw, this is from a tutorial at http://www.youtube.com/watch?v=Ihw0cfNOrr4, not my own work.
viewcontroller.h
#import <UIKit/UIKit.h>
interface calcViewController : UIViewController {
float result;
IBOutlet UILabel *calculatorScreen;
int currentOperation;
float currentNumber;
}
-(IBAction)buttonDigitPressed:(id)sender;
-(IBAction)buttonOperationPressed:(id)sender;
-(IBAction)cancelInput;
-(IBAction)cancelOperation;
#end
in the .m
#import "calcViewController.h"
#implementation calcViewController
-(IBAction)buttonDigitPressed:(id)sender {
currentNumber = currentNumber *10 + (float)[sender tag];
calculatorScreen.text = [NSString stringWithFormat:#"%2f", currentNumber];
}
-(IBAction)buttonOperationPressed:(id)sender {
if (currentOperation ==0) result = currentNumber;
else {
switch (currentOperation) {
case 1:
result = result + currentNumber;
break;
case 2:
result = result - currentNumber;
break;
case 3:
result = result * currentNumber;
break;
case 4:
result = result / currentNumber;
break;
case 5:
currentOperation = 0;
break;
}
}
currentNumber = 0;
calculatorScreen.text = [NSString stringWithFormat:#"%2f", result];
if ([sender tag] ==0) result=0;
currentOperation = [sender tag];
}
-(IBAction)cancelInput {
currentNumber =0;
calculatorScreen.text = #"0";
}
-(IBAction)cancelOperation {
currentNumber = 0;
calculatorScreen.text = #"0";
currentOperation = 0;
}
One way is to use NSNumberFormatter to format your result instead of NSString's -stringWithFormat::
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:requiredDigits];
[formatter setMinimumFractionDigits:0];
NSString *result = [formatter stringFromNumber:[NSNumber numberWithFloat:currentNumber];
The easiest way is just use [[NSNumber numberWithFloat:] stringValue]
Example:
float someFloatValue;
NSString floatWithoutZeroes = [[NSNumber numberWithFloat:someFloatValue] stringValue];
If we use %g in place of %f will truncate all zeros after decimal point.
For example
[NSString stringWithFormat:#"%g", 1.201000];
Output
1.201
This should work
NSString *result = [#(currentNumber) description];
I had the same problem. This is the code snippet that solved it (looks a lot like Caleb's solution, but that one didn't work for me, so I had to add an extra line):
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = kCFNumberFormatterDecimalStyle;
numberFormatter.maximumFractionDigits = 20;
numberFormatter.minimumFractionDigits = 0;
NSNumber *number = [[NSNumber alloc]init];
NSString *numberString = [numberFormatter stringFromNumber:number];
We can use another numberStyle and override its basic appearance, setting desired properties of an NSNumberFormatter.