// 按指定位数截取小数部分,不四舍五入 const DEFAULT_DECIMAL_NUMBER = 3 const roundNumber = function(val, num=DEFAULT_DECIMAL_NUMBER){ if(typeof val != 'number'){ return val } let demencialLength = val.toString().split(".")[1].length || 0 if(demencialLength <= num){ return val } const format = Math.pow(10,num) const newValue = Math.round(val * format) / format return newValue }