iOS Dev – Assignment #1 – Extra Task #1

Adapt the number of shown decimals to the actual result that is to be displayed.

Actually NSNumber does that all. Thus we just have to create an NSNumber from the number before we display it. At the same time we change all floats to doubles to reduce the problem of the “float feature” described before:

- (IBAction)operationButtonPressed:(UIButton *)sender {
    ...
    self.numberTextField.text = [NSString stringWithFormat:@"%@", 
         [NSNumber numberWithDouble:firstOperand]];        
    ...
}

- (IBAction)resultButtonPressed:(id)sender {
    ...
    self.numberTextField.text = [NSString stringWithFormat:@"%@", [NSNumber numberWithDouble:result]];
    ...
}
Facebooktwittergoogle_plusredditpinterestlinkedintumblrmailFacebooktwittergoogle_plusredditpinterestlinkedintumblrmail

Flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *