优化小数数字格式化

This commit is contained in:
刘祥超
2022-10-23 09:25:20 +08:00
parent a5f30b1573
commit 318c8dd566
2 changed files with 7 additions and 12 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"github.com/iwind/TeaGo/types"
"strconv"
"strings"
)
func FormatInt64(value int64) string {
@@ -50,15 +49,5 @@ func FloorFloat32(f float32, decimal int) float32 {
return f
}
var s = fmt.Sprintf("%f", f)
var index = strings.Index(s, ".")
if index < 0 {
return f
}
var d = s[index:]
if len(d) <= decimal+1 {
return f
}
return types.Float32(s[:index] + d[:decimal+1])
return types.Float32(fmt.Sprintf("%.2f", f))
}