Skip to content

Instantly share code, notes, and snippets.

@pignuante
Last active November 18, 2020 02:26
Show Gist options
  • Save pignuante/f46eb9d6bcfc3d02f9f453483273ee33 to your computer and use it in GitHub Desktop.
Save pignuante/f46eb9d6bcfc3d02f9f453483273ee33 to your computer and use it in GitHub Desktop.
func round(num float64) int {
return int(num + math.Copysign(0.5, num))
}
func floatRound(num float64, precision int) float64 {
output := math.Pow(10, float64(precision))
return float64(round(num * output)) / output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment