例如数字 32.925 四舍五入后是32.93, 129.075四舍五入后是129.08。下面两个方法都不行
function myFixed2(num, digit) {
num = parseFloat(num);
return (Math.round((num + Number.EPSILON) * Math.pow(10, digit)) / Math.pow(10, digit)).toFixed(digit);
}
//
function myFixed(num, fixed) {//修改js四舍五入
var pos = num.toString().indexOf('.'),
decimal_places = num.toString().length - pos - 1,
_int = num * Math.pow(10, decimal_places),
divisor_1 = Math.pow(10, decimal_places - fixed),
divisor_2 = Math.pow(10, fixed);
return Math.round(_int / divisor_1) / divisor_2;
}