现在的位置: 首页 > 综合 > 正文

javascript四舍五入

2013年10月08日 ⁄ 综合 ⁄ 共 202字 ⁄ 字号 评论关闭

 Number.prototype.toFixed=function(len)
{
var add = 0;
var s,temp;
var s1 = this + "";
var start = s1.indexOf(".");
if(s1.substr(start+len+1,1)>=5)add=1;
var temp = Math.pow(10,len);
s = Math.floor(this * temp) + add;
return s/temp;
}

抱歉!评论已关闭.