I've been doing some calculations in my App and only with certain number combinations I'm getting a very weird number:
extension Double {
var fives: Double { return round(self * 20) / 20 }
}
let payed: Double = 97
let price: Double = 70
let tipps: Double = 48
let discount: Double = (100 - 30) / 100
let newPrice: Double = (price * discount).fives
print(newPrice - payed + tipps)
The results should print out 0.0
(which it does in playground), but sometimes in my app it prints out 7.105427357601e-15
. I'm not doing anything asynchronously besides some animations and removing / inserting some table rows.
This "strange" behaviour is fixed when I don't use the extension fives
. When fives
is removed, then everything works just normally.
I know the information might not be enough to know what exactly is happening, but perhaps someone has an idea of what could be happening?