gpt4 book ai didi

algorithm - Xcode TextField显示数字,但是代码添加小数

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:30:35 26 4
gpt4 key购买 nike

我正在做小费计算器,这是我目前拥有的代码:(下面)。[为了让它看起来更漂亮],用户有没有办法只输入(15),让代码在后台显示.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];

}

最佳答案

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

关于algorithm - Xcode TextField显示数字,但是代码添加小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17075702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com