I currently have 2 text fields where users enter full numbers, these are then multiplied together and divided by 100 to get a desired number and shown in a label, i.e. 2400×1200/100=288.
My issue is I require the resulting number to be shown as “2.88” not “288” how can i achieve this?
My code as below
- (IBAction)myTextField:(id)sender {
}
- (IBAction)mySecondTextField:(id)sender {
}
- (IBAction)calculate {
int num1 = self.myTextField.text.intValue;
int num2 = self.mySecondTextField.text.intValue;
self.myLabel.text = [NSString stringWithFormat:@"%.2d m2", num1 * num2 / 10000];
}
Use –
instead of 10000, you need to use 10000.0. And only %0.2f is sufficient as format.