Thursday, July 3, 2014

add commas to number (e.g. 1,000) javascript function

function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}

No comments:

Post a Comment