Last active
January 28, 2017 13:10
-
-
Save tonkla/36c6b069d10d419409f5cafaaf2deb05 to your computer and use it in GitHub Desktop.
Go's math.Round(num float64, precision int)
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
func Round(num float64, precision uint) float64 { | |
pow := math.Pow(10, float64(precision)) | |
n := int((num * pow) + math.Copysign(0.5, num)) | |
return float64(n) / pow | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment