refactor(money): 统一金额分为纯整数工具

This commit is contained in:
yml2213
2026-10-30 14:33:35 +08:00
parent 85bff95042
commit 37e1980d2d
7 changed files with 156 additions and 179 deletions
+15 -7
View File
@@ -8,7 +8,6 @@ import (
"hfb_sys/backend/internal/model"
"hfb_sys/backend/internal/modules/rentergrowth"
"hfb_sys/backend/pkg/money"
"gorm.io/datatypes"
)
@@ -486,23 +485,32 @@ func readOrderSnapshotAssetNumber(raw datatypes.JSON, key string) float64 {
return readJSONNumber(snapshot[key])
}
// roundMoney 使用统一的角精度(0.1元)
// roundMoney 是订单历史链路的角精度兼容实现;新金额链路应直接使用整数分。
func roundMoney(value float64) float64 {
return money.Round(value)
if value <= 0 || math.IsNaN(value) || math.IsInf(value, 0) {
return 0
}
return math.Round(value*10) / 10
}
func roundQuantity(value float64) float64 {
return math.Round(value*100) / 100
}
// minMoney 返回较小金额(角精度)
// minMoney 返回较小金额(角精度兼容)。
func minMoney(a float64, b float64) float64 {
return money.Min(a, b)
if a < b {
return a
}
return b
}
// maxMoney 返回较大金额(角精度)
// maxMoney 返回较大金额(角精度兼容)。
func maxMoney(a float64, b float64) float64 {
return money.Max(a, b)
if a > b {
return a
}
return b
}
func minCent(a int64, b int64) int64 {