номер с запятой JS
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
kripi__
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, ",");
}
function formatMoney(n) {
return "$ " + (Math.round(n * 100) / 100).toLocaleString();
}
n = 2123000;
// =>2,123,000
var number = 3500;
console.log(new Intl.NumberFormat().format(number));
// → '3,500' if in US English locale
//ES6 Way
const numberWithCommas = (x) => {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
let n = 234234234;
let str = n.toLocaleString("en-US");
console.log(str); // "234,234,234"