// num要处理的数据,retain保留几位 function keepNum(num, retain) { num = Number(num); num = num.toFixed(retain+1).split("."); num = num[0] + "." + num[1].substring(0, retain); return num; } var num=keepNum(-0.1,6) console.log(num);
// num要处理的数据,retain保留几位 function keepNum(num, retain) { num = Number(num); num = num.toFixed(retain+1).split("."); num = num[0] + "." + num[1].substring(0, retain); return num; } var num=keepNum(-0.1,6) console.log(num);