我必须在我的应用程序中将一个大双数除以另一个,这将在 float 后显示 8 位数字。这是快速代码:
let firstValue:Double = 355531194300085860
let secondValue:Double = 100000000
let result = String(format: "%.8f", firstValue/secondValue)
print("value: \(result)")
我期望输出为 3555311943.00085860 但编译器给出这样的输出 3555311943.00085878 。为什么会这样,我该如何解决?
最佳答案
试试这个
let firstValue = NSDecimalNumber(string: "355531194300085860")
let secondValue = NSDecimalNumber(string: "100000000")
let result = firstValue.dividing(by: secondValue)
print(result)
结果:3555311943.0008586
关于swift - 如何在不快速四舍五入的情况下划分 double 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54324724/