Created
November 16, 2016 19:12
-
-
Save fever324/58a69f62501662cc0e34fa3ac019b9ab to your computer and use it in GitHub Desktop.
Roudn to Place Double Swift
This file contains 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 roundTo(places:Int) -> Double { | |
let divisor = pow(10.0, Double(places)) | |
return (self * divisor).rounded() / divisor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment