//强制保留指定位小数 function getFloatNum(num, index) { if(typeof num == "undefind" || num == null || isNaN(num)) return num; if(!index) index = 2; var _num = parseFloat(num).toFixed(parseInt(index)); return _num; }; console.log(getFloatNum(11,"3"),getFloatNum(11.1,"3"),getFloatNum("11.11","3"),getFloatNum("11.111",3),getFloatNum("11.1115",3)) // 11.000 11.100 11.110 11.111 11.111
如有表述不准确之处,欢迎指正,欢迎补充,感谢阅读。