fixD: function(num, precision) { if (num + ‘‘ === ‘0‘) { return num; } if (!num) { return ‘--‘; } var newnum = parseFloat(num) + ‘‘; if (newnum === ‘NaN‘) { return ‘--‘; } var fixNum = newnum; if (Number(num) === parseInt(Number(num))) { if (Number(precision) === 0) { return num; } else { // return `${Number(num)}.${‘0‘.repeat(precision)}` return Number(num) + ‘.‘ + ‘0‘.repeat(precision); } } if (newnum.toLowerCase().indexOf(‘e‘) > -1) { var a = newnum.toLowerCase().split(‘e‘); var b = a[0]; var c = Math.abs(parseFloat(a[1])); var d = ‘‘; var h = b.length; var i; if (a[0].split(‘.‘)[1]) { b = a[0].split(‘.‘)[0] + a[0].split(‘.‘)[1]; h = a[0].split(‘.‘)[0].length; } for (i = 0; i < c - h; i++) { d = d + ‘0‘; } fixNum = ‘0.‘ + d + b; } // 精度格式化 // precision初始化 if (!precision) { return fixNum; } if (parseFloat(num) + ‘‘ === ‘NaN‘) { return fixNum; } var fNum = (fixNum + ‘‘).split(‘.‘); if (!fNum[1]) { fixNum = parseFloat(fixNum).toFixed(precision); } else if (precision === 0) { fixNum = parseInt(fixNum, 10); } else if (fNum[1].length > precision) { fixNum = fNum[0] + ‘.‘ + fNum[1].substr(0, precision); } else { fixNum = parseFloat(fixNum).toFixed(precision); } return fixNum; },