fix logger,cache

This commit is contained in:
2025-10-02 18:06:23 +08:00
parent 10ee9bba10
commit f934472e50
9 changed files with 869 additions and 12 deletions

34
utils/fmt.go Normal file
View File

@@ -0,0 +1,34 @@
package utils
import (
"strconv"
"strings"
)
func FloatRoundString(in float64, place int) string {
return Float64ToString(FloatRound(in, place))
}
func FloatRound(in float64, place int) float64 {
// 限制 place 范围在合理区间
if place < 0 {
place = 0
}
// 使用 strconv.FormatFloat 直接格式化,避免多次条件判断
str := strconv.FormatFloat(in, 'f', place, 64)
num, _ := strconv.ParseFloat(str, 64)
return num
}
func RateToFloat64(s string) float64 {
// 去掉百分号
s = strings.TrimSuffix(s, "%")
// 转换为 float64
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return 0
}
return f / 100
}