js thousand separator and change td content

Posted rojas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js thousand separator and change td content相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode --- 1556. Thousand Separator 解题报告

LeetCode --- 1556. Thousand Separator 解题报告

to the monkey and the frog.for an eternity of ten thousand tales.什么意思?

VSCode platformIO IDE报backslash and newline separated by space警告

实现PHP的编译执行分离(separating compilation and execution)

[BTS] BizTalk EDI character set and separator settings