## 实现 ``` function formatMoney(val) { if (!val) return; return val.toString().replace(/(?=\B(?:\d{3})+\b)(\d{3}(?:\.\d+$)?)/g,',$1'); } ``` ## 测试 