Skip to content

Instantly share code, notes, and snippets.

@fuxingloh
Created November 15, 2015 06:32
Show Gist options
  • Select an option

  • Save fuxingloh/98c1fa0f51b0807a5aea to your computer and use it in GitHub Desktop.

Select an option

Save fuxingloh/98c1fa0f51b0807a5aea to your computer and use it in GitHub Desktop.
Swift: round down double to x decimal places
extension Double {
/// Rounds the double to decimal places value
func roundToPlaces(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return round(self * divisor) / divisor
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment