js格式化合计金额

var summoney=1040.010400000000000001;

var totalMoney=parseFloat(summoney).toFixed(2);
var arry=totalMoney.split(".");
if(arry[0].length>3){
totalMoney=arry[0].toString().replace(/(\d+?)(?=(?:\d{3})+$)/g,
"$1,")+"."+arry[1];
}

print: 1,040.01

 

posted @ 2017-08-29 10:43  chunming  阅读(189)  评论(0编辑  收藏  举报