Last active
January 7, 2021 18:52
-
-
Save MoussaHellal/95805fc4c9e93047c83af60fdbea8b3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Double { | |
func rounded(toPlaces places:Int) -> Double { | |
let divisor = pow(10.0, Double(places)) | |
return (self * divisor).rounded() / divisor | |
} | |
} | |
let number = 34.33356 | |
print(number.rounded(toPlaces: 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment