I have a double value as 22.368511 I want to round it to 2 decimal places. i.e. it should return 22.37
How can I do that?
I use the solution posted by Umberto Raimondi extending type Double:
extension Double { func roundTo(places:Int) -> Double { let divisor = pow(10.0, Double(places)) return (self * divisor).rounded() / divisor } }