/** * 统一金额处理工具函数 * 全项目金额精度统一为角(0.1元) */ /** * 将金额四舍五入到角精度(0.1元) * @example roundMoney(12.34) -> 12.3 * @example roundMoney(12.36) -> 12.4 */ export function roundMoney(value: number): number { return Math.round(value * 10) / 10 } /** * 格式化金额为字符串(保留1位小数) * @example formatMoney(12.3) -> "12.3" * @example formatMoney(12.0) -> "12.0" */ export function formatMoney(value: number | undefined | null): string { const num = Number(value || 0) return roundMoney(num).toFixed(1) } /** * 格式化金额并添加货币符号 * @example formatMoneyWithSymbol(12.3) -> "¥12.3" */ export function formatMoneyWithSymbol(value: number | undefined | null): string { return `¥${formatMoney(value)}` }