You could use an extension on Double, like I do when I'm displaying prices, e.g.:
extension Double {
func rounded(toPlaces places: Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
Then use it like this:
print(1.256.rounded(toPlaces: 2))
Topic:
App & System Services
SubTopic:
General
Tags: