Playground demonstration for rounding a double number to N places.
Make it a part of your own extension ⚙
import Foundation
extension Double {
/// Rounds the double to N number of decimal places
mutating func round(to places: Int) -> Double {
let divisor = pow(10.0, Double(places))
return Darwin.round(self * divisor) / divisor
}
}
There are multiple ways to achive this but I prefer this way! ✏
Web: Khawaja Farooq
Twitter: @khfarooq
Medium: @khfarooq