1. 程式人生 > >js thousand separator and change td content

js thousand separator and change td content

color for doc .get log content cti var tostring

js thousand seprator and change TD content

// integer 
function addCommas(n){
    var rx=  /(\d+)(\d{3})/;
    return String(n).replace(/^\d+/, function(w){
        while(rx.test(w)){
            w= w.replace(rx, $1,$2);
        }
        return w;
    });
}

//decimal
function thousandBitSeparator(num) {
        
return num && num .toString() .replace(/(\d)(?=(\d{3})+\.)/g, function($0, $1) { return $1 + ","; }); } // change table td content by getElementsByClassName() function changeTDcontent(){ var olist=document.getElementsByClassName("cl_id");
for(var i=0;i<olist.length;i++){ var c=olist[i].innerHTML; olist[i].innerHTML=addCommas(c); } }

js thousand separator and change td content