//强制保留指定位小数 function getFloatNum(num, index) { if(typeof num == "undefind" || num == null || num == "" || 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
如有表述不准确之处,欢迎指正,欢迎补充,感谢阅读。
原文地址:https://www.cnblogs.com/wangzhenyu666/p/8302759.html
时间: 2024-10-17 21:10:05