gpt4 book ai didi

iOS计时器/工资计算器

转载 作者:行者123 更新时间:2023-11-28 22:09:24 29 4
gpt4 key购买 nike

我正在制作一个计时器,它接受每小时工资输入并跟踪每秒赚多少钱。计时器上的格式工作得很好,但一旦便士达到 99,它就会清零,只会增加美元。这是我得到的。

seconds = (int) (elapsedTime = (elapsedTime - (minutes *60)));
pennies = seconds * (ratePerSecond * 100);
if(pennies > 99){

dollars++;
pennies = 0;
}

self.moneyDisplay.text = [NSString stringWithFormat: @"$%02d.%02d", dollars, pennies];

最佳答案

试试这个:

seconds = (int) (elapsedTime = (elapsedTime - (minutes *60)));
pennies = seconds * (ratePerSecond * 100);
float dollars = pennies / 100.0;
self.moneyDisplay.text = [NSString stringWithFormat: @"$%.2f", dollars];

或:

seconds = (int) (elapsedTime = (elapsedTime - (minutes *60)));
pennies = seconds * (ratePerSecond * 100);
int cents = pennies % 100;
int dollars = pennies / 100;
self.moneyDisplay.text = [NSString stringWithFormat: @"$%02d.%02d", dollars, cents];

关于iOS计时器/工资计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23259044/

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