0

我正在制作小费计算器,这是我目前拥有的代码:(下)。[为了让它看起来不错],有没有办法让用户只输入 (15),然后让代码在后台显示 0.15?谢谢

- (IBAction)calcTapped:(id)sender {

NSString *billAmountString = [billAmountTextField text];

float billAmountFloat = [billAmountString floatValue];

NSString *tipPercentString = [tipPercentTextField text];

float tipPercentFloat = [tipPercentString floatValue];

float tipAmount = billAmountFloat * tipPercentFloat;

NSString *result = [NSString stringWithFormat:@"Tip: %0.2f",

                    tipAmount];
[resultLabel setText:result];

}

4

1 回答 1

1

尝试从文本字段中检索字符串,将其转换为 NSNumber(或浮点数),然后除以 100。你知道,因为 15/100 = 0.15。

于 2013-06-12T21:49:49.717 回答