带小数点的 var a = 8462948.2453; console.log(a.toLocaleString()) //8,462,948.245 不带小数点的 num.toString().replace(/(\d)(?=(\d{3})+$)/g,'$1,') 满足两者情况的 function numFormat(num) { var c = (num.toString().indexOf ('.') !== -1) ? num.toLocaleString() : num.toStrin
添加千分位处理: function fmoney(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(&qu
/** * 千分位格式化数字 * * @param s * 传入需要转换的数字 * @returns {String} */ function formatNumber(s) { if (!isNaN(s)) { s = $.trim(s + ""); var l = s.split(".")[0].split("").reverse(), r = s.indexOf(".") >= 0 ? "."
JS实现转换千分位计数 350000.00-------350,000.00 var num=0;function format (num) { return (num.toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');} var num = 12345;console.log(format(num));-----------------输出12,345.00 js方法toFixed(n):将number转换为小数点