<body> <div id="container"></div> <script> var formatNumber = function(str,split){ var type = typeof str; switch (type){ case "number": str = str.toString(); case "string": return str.replace(/(\d+?)(?=(?:\d{3})+$)/g,"$1"+split); break; default: return ; } },arr=["0.3000","22.356","444.456",123456.56,"1","111","1211","123456","1457910","aaaa",{"name":"zhangsan"}],str="<table width='50%' cellspacing='0' cellpadding='0' border='1' align='center'>"; for(var i = 0; i< arr.length;i++){ var ss = arr[i],format = formatNumber(ss,","); str += "<tr><td>"+ss+"</td><td>"+format+"</td></tr>"; } str+="</table>"; document.getElementById("container").innerHTML = str; </script> </body>@H_301_2@
结果如下图: 原文链接:https://www.f2er.com/regex/362668.html