All,
I have a floating number issue that I need help with. I just started with Objective-C and this seems to be a pretty simple solution, but I’m at a loss after my search. In short, I’m adding the numerical input from four TextFields together and displaying the answer in a UILabel. My answer is in the correct decimal format, but only displays 0.00 and not the correct sum. Im sure it it something to do with converting between string and float, but I need some assistance:
- (IBAction)Calc1:(id)sender {
int result = [oranges.text doubleValue] +
[bananas.text doubleValue] +
[grapes.text doubleValue] +
[pears.text doubleValue];
text123.text = [NSString stringWithFormat:@"%.1f", result];
}
You probably want to declare result as a double…