angular 数字逗号分隔_数字显示千分位,将数字转换成千分位形式(用逗号隔开)...

var weekValue=10000000;

if(weekValue!=0){

weekValue = addThousands(weekValue);

console.log(weekValue);

}

function addThousands(number) {

if(number==0){

return number;

}else if(number==0.0){

return number;

}

var num = number + "";

num = num.replace(new RegExp(",","g"),"");

// 正负号处理

var symble = "";

if(/^([-+]).*$/.test(num)) {

symble = num.replace(/^([-+]).*$/,"$1");

num = num.replace(/^([-+])(.*)$/,"$2");

}

if(/^[0-9]+(\.[0-9]+)?$/.test(num)) {

var num = num.replace(new RegExp("^[0]+","g"),"");

if(/^\./.test(num)) {

num = "0" + num;

}

var decimal = num.replace(/^[0-9]+(\.[0-9]+)?$/,"$1");

var integer= num.replace(/^([0-9]+)(\.[0-9]+)?$/,"$1");

var re=/(\d+)(\d{3})/;

while(re.test(integer)){

integer = integer.replace(re,"$1,$2");

}

return symble + integer + decimal;

} else {

return number;

}

}

你可能感兴趣的:(angular,数字逗号分隔)