移动端适用:给金钱每3位一个逗号,

//var price=parseInt(data[0].price).toLocaleString();//仅支持PC端不支持移动端

//金钱价格每3位一个逗号
function addCommas(nStr)
{
nStr += '';//改变成字符串
x = nStr.split('.');
x1 = x[0];
//console.log(x.length)
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(d+)(d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
原文地址:https://www.cnblogs.com/pengchengzhong/p/6401714.html