gpt4 book ai didi

iphone - Objective-C 中的循环 double

转载 作者:太空狗 更新时间:2023-10-30 03:24:49 24 4
gpt4 key购买 nike

我有双数,格式如 34.123456789。如何将其更改为 34.123?

我只想要小数点后 3 位数字。

最佳答案

您可以使用 [NSString stringWithFormat:@"%.3f",d] 将其打印到小数点后 3 位。

您可以用 round(d*1000)/1000 对其进行近似舍入,但当然不能保证准确,因为 1000 不是 2 的幂。

关于iphone - Objective-C 中的循环 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3476317/

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