Numéro avec des virgules 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, ',');
}
//ES6 Way
const numberWithCommas = (x) => {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
formatedNumber = new Intl.NumberFormat().format(2561556862056.12)
console.log(formatedNumber) // "2,561,556,862,056.12"
let n = 234234234;
let str = n.toLocaleString("en-US");
console.log(str); // "234,234,234"
foramtNumber = (num,div=",")=>{
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, div);
}