首页 > 其他 > 详细

重写toFixed

时间:2015-11-21 11:46:30      阅读:251      评论:0      收藏:0      [点我收藏+]

重写了toFixed

Number.prototype.toFixed = function(c){
var self = this,
re = Math.round(self * Math.pow(10,c)) / Math.pow(10,c) + "";
if( c==0 ) return re;
(re.indexOf(".") == -1) && (re += ".");
var length = re.split(".")[1].length,
_length = c - length;
if(_length > 0){
re += Math.pow(10,_length).toString().slice(1);
}
return re ;
}

重写toFixed

原文:http://www.cnblogs.com/anson0415/p/4983220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!