javascript中怎么只取到小数点后两位?

例 sum=parseFloat(8.99)+parseFloat(7.50);
等到值为:16.4900000002
怎么只取到小数点后两位?

<script language="JScript">
Number.prototype.toFixed=function(num)
   {
   //重新构造toFixed方法,IE5.0+
   with(Math)this.NO=round(this.valueOf()*pow(10,num))/pow(10,num);
   return String(/\./g.exec(this.NO)?this.NO:this.NO+"."+String(Math.pow(10,num)).substr(1,num));
   }
alert((12.9299).toFixed(2));
alert((12.9999).toFixed(2));
</script> 


.toFixed(2)好象是不能四舍五入

你可能感兴趣的:(JavaScript,prototype)