js保留小数(不四舍五入)
function formatDecimal(num, decimal) { num = num.toString() let index = num.indexOf('.') if (index !== -1) { num = num.substring(0, decimal + index + 1) } else { num = num.substring(0) } return parseFloat(num).toFixed(decimal) }
console.log(formatDecimal(3.1415926,6)) ---> 3.141592