<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add a comma thousandth every three digits to a number</title>
<style type="text/css">
</style>
</head>
<body>
<script type="text/javascript">
function farmat(mun) {
if (mun === null) return;
var m = parseInt(mun).toString();
var len = m.length;
if (len <= 3) return m;
var n = len % 3;
if (n > 0) {
return m.slice(0,n)+","+m.slice(n,len).match(/\d{3}/g).join(",")}else {
return m.slice(n,len).match(/\d{3}/g).join(",")}}var a =farmat(1000000)
console.log(a); //1,000,000
</script>
</body>
</html>
Copy the code
\