发布于 2021-12-21 22:29:59
似乎舍入模式7,即ROUND_HALF_CEIL
与_.round()匹配
Decimal.set({rounding: Decimal.ROUND_HALF_CEIL});
console.log(Decimal.rounding,'Decimal.rounding');
// 7 'Decimal.rounding'
var test1 = Decimal(3.15).toDP(1).toString();
console.log(test1,'test1');
// 3.2 test1
var test2 = Decimal(-3.15).toDP(1).toString();
console.log(test2,'test2');
// -3.1 test2
var test3 = _.round(3.15, 1);
console.log(test3,'test3');
// 3.2 test3
var test4 = _.round(-3.15, 1);
console.log(test4,'test4');
// -3.1 test4
注意:这不是一个详尽的测试。我记得从经验中,模式1,2,5,6,8和9是不正确的。
https://stackoverflow.com/questions/70442240
复制相似问题