Files
go-easy-utils/mathUtil/round.go
jeffery f97913a2bc Feature/math util (#22)
Development supports the math package
2023-04-12 11:10:07 +08:00

18 lines
307 B
Go

package mathUtil
import (
"math"
"reflect"
)
// Round 对float数据四舍五入
func Round[T float32 | float64](num T) int {
switch reflect.ValueOf(num).Kind() {
case reflect.Float32:
return int(math.Round(float64(num)))
case reflect.Float64:
return int(math.Round(float64(num)))
}
return 0
}