Reputation: 428
I have to divide a big double number by another in my application which will show 8 digit after floating point. Here is the swift code:
let firstValue:Double = 355531194300085860
let secondValue:Double = 100000000
let result = String(format: "%.8f", firstValue/secondValue)
print("value: \(result)")
I am expecting the output as 3555311943.00085860 but compiler giving output like this 3555311943.00085878 . Why this is happening and how can i fix it?
Upvotes: 0
Views: 1840
Reputation: 237
Try this
let firstValue = NSDecimalNumber(string: "355531194300085860")
let secondValue = NSDecimalNumber(string: "100000000")
let result = firstValue.dividing(by: secondValue)
print(result)
Result: 3555311943.0008586
Upvotes: 2