JS 数字千分位互转
* 数字格式转换成千分位
*@param{Object}num
*/
function commafy(num){
if((num+"").trim()==""){
return "";
}
if(isNaN(num)){
return "";
}
num = num+"";
if(/^.*\..*$/.test(num)){
var pointIndex =num.lastIndexOf(".");
var intPart = num.substring(0,pointIndex);
var pointPart =num.substring(pointIndex+1,num.length);
intPart = intPart +"";
var re =/(-?\d+)(\d{3})/;
while(re.test(intPart)){
intPart =intPart.replace(re,"$1,$2");
}
num = intPart+"."+pointPart;
}else{
num = num +"";
var re =/(-?\d+)(\d{3})/;
while(re.test(num)){
num =num.replace(re,"$1,$2");
}
}
return num;
}
/**
* 去除千分位
*@param{Object}num
*/
function delcommafy(num){
if((num+"").trim()==""){
return "";
}
num=num.replace(/,/gi,'');
returnnum;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。