1function numberWithCommas(x) {
2 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
3}
1//ES6 Way
2const numberWithCommas = (x) => {
3 return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
4}
1formatedNumber = new Intl.NumberFormat().format(2561556862056.12)
2console.log(formatedNumber) // "2,561,556,862,056.12"
1foramtNumber = (num,div=",")=>{
2 return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, div);
3
4}