- let sgToFixed = (num,digit=2) => {
- //num是数值;digit是保留有效数字位数
- let nums=(num||0).toString().split('.');
- return nums[0]+'.'+(nums[1]||'0').padEnd(digit, "0");
- }
sgToFixed(0,'3'); //0.000
sgToFixed(1,'2'); //1.00
sgToFixed(1); //1.00
sgToFixed(1.1,'2'); //1.10
sgToFixed(1.11); //1.11