Skip to content

Instantly share code, notes, and snippets.

@henryhamon
Created June 13, 2017 11:45
Show Gist options
  • Save henryhamon/25bd9ad91bee545519d61e0b341b4481 to your computer and use it in GitHub Desktop.
Save henryhamon/25bd9ad91bee545519d61e0b341b4481 to your computer and use it in GitHub Desktop.
func to round
func Round(val float64, roundOn float64, places int) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
digit := pow * val
_, div := math.Modf(digit)
if div >= roundOn {
round = math.Ceil(digit)
} else {
round = math.Floor(digit)
}
newVal = round / pow
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment