Recently, I have been involved in the processing of a lot of monetary values when developing a mall. I will soon have to convert the data (for example: 12345-->1,2345...)
//Format the number fmoney("12345.675910", 3) , return 12,345.676
fmoneyFormatPoint : function(s, n) { n = n > 0 && n <= 20 ? n : 2; s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + ""; var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1]; t = ""; for (i = 0; i < l.length; i++) { t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : ""); } var amt = t.split("").reverse().join("") + "." + r; return amt; //返回带有逗号的值 //return amt.replace(new RegExp(/,/g),'');//返回没有带逗号的值 }