Hey guys. I have coded a simple calculator and it all works perfectly. My only issue is when i type in a number, say for example i push number 7, it will show as 7.000000 instead of just 7. How can i remove these .000000's? And if there is a way to add percent to it.
Here's my .M code:
.M
Code:
// -- CALCULATOR CODE START --
-(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;
}
// -- CALCULATOR CODE END --
Any help much appreciated!