js里边取float数的精度的方法 toFixed()
toFixed() 方法可把 Number 四舍五入为指定小数位数的数字。
toFixed() 里面的数为 0- 20 之间的整数。
var a = 1.23456
a.toFixed(2) = 1.23
toFixed 方法有bug,不同的浏览器对它的解析不一样。比如,0.009.toFixed(2)在firefox下 为0.01 而在IE7下为
0.00。详见:http://www.cnblogs.com/MythYsJh/archive/2009/02/13/1389843.html
解决办法:
重写
Number.prototype.toFixed = function ( fractionDigits )
{
return (parseInt( this * Math.pow( 10 , fractionDigits ) + 0.5 )/Math.pow(10,fractionDigts)).toString();
}