gpt4 book ai didi

iphone - 在 UILabel 中显示 float

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:17 24 4
gpt4 key购买 nike

我在 UILabel 中使用 float 时遇到问题。

float doubleNum;

floatNum = 10 / 20;

cashLabel.text = [[NSString alloc] initWithFormat:@"%f", floatNum];

如果我使用“floatNum = 10/10;”它正确返回“1.000000000”,但是,如果我输入“floatNum = 10/20”,它会返回“0.0000000”。我已经尝试了我所知道的一切,但它不起作用。我知道这是一个愚蠢的错误,但我想不通。

节日快乐。 :)

最佳答案

您需要将其中一个整数转换为 float 。

尝试将分割线替换为:

float floatNum = (float) 10 / 20;

你应该会得到正确的答案。

或者,如果可能的话,只在你的部门使用花车:

float floatNum = 10.0f / 20.0f;

应该也可以

关于iphone - 在 UILabel 中显示 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8632060/

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