function numberWithCommas(x) {
return x.toString().replace(/B(?=(d{3})+(?!d))/g, ',');
}
function numberWithCommas(x) {
return x.toString().replace(/B(?<!.d*)(?=(d{3})+(?!d))/g, ",");
}
// A more complex example:
number.toLocaleString(); // "1,234,567,890"
// A more complex example:
var number2 = 1234.56789; // floating point example
number2.toLocaleString(undefined, {maximumFractionDigits:2}) // "1,234.57"
var number = 3500;
console.log(new Intl.NumberFormat().format(number));
// → '3,500' if in US English locale
var number = 3500;
console.log(number.toLocaleString());
const totalBalance = (x, y) => {
let total = parseInt(x.replace(/,/g, "")) + parseInt(y.replace(/,/g, ""));
return total.toString().replace(/B(?<!.d*)(?=(d{3})+(?!d))/g, ",");
//Output structure will be like:23,236//
};
numberWithCommas(number) {
return number.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
},