向上取整
const formatRoundNum = (num, pre) => {
if (!num || num === 0 || typeof num !== Number) return 0;
return (Math.round(num * Math.pow(10, pre)) / Math.pow(10, pre)).toFixed(pre);
};
formatRoundNum(75.75999999999999,2)
// '75.76'
向下取整
const formatRoundNum = (num, pre) => {
if (!num || num === 0 || typeof num !== Number) return 0;
return (Math.floor(num * Math.pow(10, pre)) / Math.pow(10, pre)).toFixed(pre);
};
formatRoundNum(75.75999999999999,2)
// '75.75'
返回Number类型
const formatRoundNum = (num, pre) => {
if (!num || num === 0 || typeof num !== Number) return 0;
return (Math.floor(num * Math.pow(10, pre)) / Math.pow(10, pre));
};
formatRoundNum(75.75999999999999,2)
// 75.75