Skip to content

Instantly share code, notes, and snippets.

@tonkla
Last active January 28, 2017 13:10
Show Gist options
  • Save tonkla/36c6b069d10d419409f5cafaaf2deb05 to your computer and use it in GitHub Desktop.
Save tonkla/36c6b069d10d419409f5cafaaf2deb05 to your computer and use it in GitHub Desktop.
Go's math.Round(num float64, precision int)
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