Open wingmeng opened 5 years ago
一般
优秀、良好、一般、差劲
1.005.toFixed(2)
的测试用例,期望返回 1.01
实际返回 1.00
。var oldtoFixed = Number.prototype.toFixed
Number.prototype.toFixed = function(digits){
var length = (parseFloat(this) + '').replace(/^\d+\.?/, '').length;
var len = length > digits ? length : digits;
var number = Number(this) + Math.pow(10, -len-1);
return oldtoFixed.call(number, digits);
}
题目:
我的回答:
0.6.toFixed(0)
1.6.toFixed(0)
0.035.toFixed(2)
0.045.toFixed(2)
测试用例: