评论需要添加功能,提交订单有问题

This commit is contained in:
bobobobo
2025-12-26 02:15:32 +08:00
parent 1aab94bbc3
commit bb02cb22c0
32 changed files with 2844 additions and 117 deletions

View File

@@ -4,12 +4,28 @@
* @returns
*/
export const formatRMB = amount => {
const formatted = new Intl.NumberFormat('zh-CN', {
style: 'currency',
currency: 'CNY',
minimumFractionDigits: 2,
maximumFractionDigits: 2
}).format(amount)
// 处理 null、undefined 或非数字输入
if (amount == null || amount === '') {
return '0.00'
}
return formatted.replace(/^[¥\s]+/, '') // 移除开头的 ¥ 和可能的空格
// 转为数字
let num = Number(amount)
if (isNaN(num)) {
return '0.00'
}
// 保留两位小数(四舍五入)
num = Math.round(num * 100) / 100
// 转为固定两位小数字符串
let str = num.toFixed(2)
// 分离整数和小数部分
const [integer, decimal] = str.split('.')
// 添加千分位分隔符(从右往左每三位加逗号)
const formattedInteger = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return `${formattedInteger}.${decimal}`
}