Created
November 15, 2015 06:32
-
-
Save fuxingloh/98c1fa0f51b0807a5aea to your computer and use it in GitHub Desktop.
Swift: round down double to x decimal places
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 { | |
| /// 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