数字千位加逗号js

<script  type= "text/javascript">
var num_s = "1232134456.546 ";alert(parseFloat(num_s).toLocaleString());
</script>
<script type="text/javascript">
function format_number(n){
var b=parseInt(n).toString();
var len=b.length;
if(len<=3){return b;}
var r=len%3;
return r>0?b.slice(0,r)+","+b.slice(r,len).match(/\d{3}/g).join(","):b.slice(r,len).match(/\d{3}/g).join(",");
}

var a="53669988.000";
alert(format_number(a));
alert(format_number("wahh"));
alert(format_number(0));
alert(format_number(6698.0023));
</script>
posted @ 2015-12-08 17:55  安雅然  阅读(462)  评论(0编辑  收藏  举报