1function formatMoney(n) {
2 return "$ " + (Math.round(n * 100) / 100).toLocaleString();
3}
4
5n = 2123000;
6// =>2,123,000
1//ES6 Way
2const numberWithCommas = (x) => {
3 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
4}
1foramtNumber = (num,div=",")=>{
2 return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, div);
3
4}