Js数字千分位

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>标题页</title>
</head>
<body>
<script language="JavaScript"> 
function millon()
{
  var s=parseFloat(myNum.value); //获取小数型数据
  s+="";
  if(s.indexOf(".")==-1) s+=".0";//如果没有小数点,在后面补个小数点和0
  if(/\.\d$/.test(s)) s+="0";   //正则判断
  while(/\d{4}(\.|,)/.test(s))  //符合条件则进行替换
    s=s.replace(/(\d)(\d{3}(\.|,))/,"$1,$2");//每隔3位添加一个,
  alert(s);
}
</script>
<input type="text" name="myNum" value="1234567890.08"><input type="button" value="millon" onclick="millon()">
</body>
</html>

 

你可能感兴趣的:(JavaScript)