Skip to content

Instantly share code, notes, and snippets.

@MoussaHellal
Last active January 7, 2021 18:52
Show Gist options
  • Save MoussaHellal/95805fc4c9e93047c83af60fdbea8b3f to your computer and use it in GitHub Desktop.
Save MoussaHellal/95805fc4c9e93047c83af60fdbea8b3f to your computer and use it in GitHub Desktop.
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