package money import ( "fmt" "math" ) // Round 将金额四舍五入到角(0.1元),统一全项目金额精度 // 例如:12.34 -> 12.3, 12.36 -> 12.4, 12.35 -> 12.4 func Round(value float64) float64 { return math.Round(value*10) / 10 } // Min 返回两个金额中较小的值(角精度) func Min(a, b float64) float64 { if a < b { return Round(a) } return Round(b) } // Max 返回两个金额中较大的值(角精度) func Max(a, b float64) float64 { if a > b { return Round(a) } return Round(b) } // Format 格式化金额为字符串(保留1位小数) // 例如:12.3 -> "12.3", 12.0 -> "12.0" func Format(value float64) string { rounded := Round(value) return fmt.Sprintf("%.1f", rounded) } // FormatWithSymbol 格式化金额并添加货币符号 // 例如:12.3 -> "¥12.3" func FormatWithSymbol(value float64) string { return "¥" + Format(value) }