保留两位小数不四舍五入
function retain(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)
}
var nums=retain(33.45678, 2);
console.log(nums) //33.45
function retain2(num,d){
return (parseInt(num*100)/100).toFixed(d)
}
var nums=retain2(33.45678, 2);
console.log(nums)//33.45
var num=Math.floor(15.7784514000 * 100) / 100 ; //15.77
console.log(typeof num) //number