round.go 155 B

12345678910
  1. package util
  2. import (
  3. "math"
  4. )
  5. func Round(f float64, n int) float64 {
  6. pow10_n := math.Pow10(n)
  7. return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
  8. }