Add commas to a number - Node.js Number

Node.js examples for Number:Format

Description

Add commas to a number

Demo Code

// http://stackoverflow.com/questions/3883342/add-commas-to-a-number-in-jquery
function commaSeparateNumber(val){
    while (/(\d+)(\d{3})/.test(val.toString())){
       val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
    }//ww w . j a va  2  s .  co m
    return val;
}

Related Tutorials