<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>对一个数字每3位加一个逗号 千分符</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>