number with commas js

72

add comma to number javascript -

var n = 34523453.345
n.toLocaleString()
"34,523,453.345"

commas for thousands js -

var number = 3500;

console.log(new Intl.NumberFormat().format(number));
// → '3,500' if in US English locale

add commas to a number javascript -

function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

Comments

Submit
0 Comments