@ssports_fe/ssutils
Version:
17 lines (14 loc) • 406 B
JavaScript
/**
* @file 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
* @date 2018-03-01
* @author sunshaocheng
*/
/**
* 四舍五入
*/
const round = (num, ratio) => {
const base = Math.pow(10, ratio);
return divide(Math.round(times(num, base)), base);
};
module.exports = round;