<script language="JavaScript" type="text/javascript">
function formatNumber(num){
if(!/^(/+|-)?(/d+)(/./d+)?$/.test(num)){
return num;
}
var a = RegExp.$1,b = RegExp.$2,c = RegExp.$3;
var re = new RegExp().compile("(
//d)(//d{3})(,|$)");
while(re.test(b)){
b = b.replace(re,"$1,$2$3");
}
return a +""+ b +""+ c;
}
var num=1234567/3;
alert("num="+num+",四舍五入:"+Math.round(num)+",两位有效数字:"+num.toFixed(2)+",添加千位分隔符:"+formatNumber(num));
</script>