Add Commas

function addCommas (n)
{
    var  number_string = new String(n);
    var  real_number = number_string.split('.');
    var  integer_part = real_number[0];
    var  fraction_part = (1 < real_number.length)? ('.'+real_number[1]): '';
    var  re = /(\d+)(\d{3})/;

    while (re.test(integer_part)) {
        integer_part = integer_part.replace(re, '$1'+','+'$2');
    }
    return integer_part+fraction_part;
}