float62 32 格式化为两位

This commit is contained in:
2026-08-31 11:21:04 +08:00
parent 2a6cd21ec4
commit 9e8e2dd8d8
7 changed files with 835 additions and 1 deletions
+13
View File
@@ -621,3 +621,16 @@ func UniqueStr(arr []string) []string {
}
return res
}
// Float 泛型约束,只允许 float32 / float64
type Float interface {
~float32 | ~float64
}
// RoundFloat 四舍五入保留n位小数,泛型版本
func RoundFloat[T Float](val T) T {
shift := math.Pow10(NumberTwo)
f := float64(val)
res := math.Round(f*shift) / shift
return T(res)
}