Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created August 25, 2020 16:22
Show Gist options
  • Save martinusso/9ca623b04348874926665d3c443fbe9e to your computer and use it in GitHub Desktop.
Save martinusso/9ca623b04348874926665d3c443fbe9e to your computer and use it in GitHub Desktop.
golang round
func Round(input float64) int {
var result float64
if input < 0 {
result = math.Ceil(input - 0.5)
} else {
result = math.Floor(input + 0.5)
}
// only interested in integer, ignore fractional
i, _ := math.Modf(result)
return int(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment