格式化金额
-
格式化规则:
- 整数位3位加
','
分割 - 小数位保留
limit
位
function formatAmount(amount, limit = 4) { let a, b; if (typeof amount == 'number') { [a, b] = amount.toFixed(limit).split(".") } else { [a, b] = amount.split(".") b = b || '' while (b.length < limit) { b += "0" } } return `${a.replace(/\B(?=(\d{3})+(?!\d))/g, ",")}.${b}` }
- 整数位3位加