我正在运行以下带有圆形函数的代码。
let percentage = round((progress / maxValue) * 100)
但是它不断返回数字,例如:15.0、25.0、35.0 等。
我希望它返回:15、25、35,基本上是 0 位小数。
我该怎么做?
干杯! :D
最佳答案
那是因为 round() 返回的是 float ,而不是整数:
如果你想要一个整数,你必须转换它:
let percentage = Int(round((progress / maxValue) * 100))
关于swift - 四舍五入 INT 使其保留 0 个小数位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42675780/