1

The standard swift's round() function just cuts off everything and leaves 1 place after the point.

1 Answers1

0
extension Double {
    // Rounds the double to decimal places value
    // Usage: (doubleVar).roundToPlaces(x) 
    // Where x is the number of places
    func roundToPlaces(places:Int) -> Double {
        let divisor = pow(10.0, Double(places))
        return round(self * divisor) / divisor
    }
}

Source: Rounding a double value to x number of decimal places in swift

Community
  • 1
  • 1
GeeMitchey
  • 134
  • 1
  • 3
  • 13