数字每个四位以空格隔开

数字每个四位以空格隔开
//格式化金额
var numberFormat = $(".num"); //一串数组
function spliteArr(arr){
    //alert(numberFormat); //
    for(var j=0;j<$(numberFormat).length;j++){
        var bb = $(numberFormat).eq(j).text().replace(/(.)(?=[^$])/g,"$1,").split(",");       //字符串转化为数组
        var zz= bb.reverse();
        var res = "";
        for(var i=zz.length-1;i>=0;i--){
            if(i%4==0&&i>0){
                res+= zz[i]+" ";
            }else{
                res+=zz[i];
            }
        }
        console.log(res);
        $(numberFormat).eq(j).text(res) ;
    }
 
}

转载于:https://www.cnblogs.com/shuxin6009/p/5889018.html

你可能感兴趣的:(数字每个四位以空格隔开)