优化toFixed 5 进位问题

This commit is contained in:
java110 2021-12-20 11:24:34 +08:00
parent 46dfd455db
commit e3d576e5a7

View File

@ -540,9 +540,9 @@
tmpProTypes = tmpProTypes.indexOf("\r") > 0 ? tmpProTypes.replace("\r/g", "") : tmpProTypes; tmpProTypes = tmpProTypes.indexOf("\r") > 0 ? tmpProTypes.replace("\r/g", "") : tmpProTypes;
let tmpType = tmpProTypes.indexOf("\n") > 0 let tmpType = tmpProTypes.indexOf("\n") > 0 ?
? tmpProTypes.split("\n") tmpProTypes.split("\n") :
: tmpProTypes.split(","); tmpProTypes.split(",");
let propsJs = "\nlet $props = {};\n"; let propsJs = "\nlet $props = {};\n";
for (let typeIndex = 0; typeIndex < tmpType.length; typeIndex++) { for (let typeIndex = 0; typeIndex < tmpType.length; typeIndex++) {
let type = tmpType[typeIndex]; let type = tmpType[typeIndex];
@ -615,8 +615,8 @@
let extPos = _js.indexOf("vc.extends"); let extPos = _js.indexOf("vc.extends");
let tmpProTypes = _js.substring(extPos, _js.length); let tmpProTypes = _js.substring(extPos, _js.length);
let pos = tmpProTypes.indexOf("{") + 1; let pos = tmpProTypes.indexOf("{") + 1;
_js = _js.substring(0, extPos) + tmpProTypes.substring(0, pos).trim() _js = _js.substring(0, extPos) + tmpProTypes.substring(0, pos).trim() +
+ "\nnamespace:'" + namespace.trim() + "',\n" + tmpProTypes.substring(pos, tmpProTypes.length); "\nnamespace:'" + namespace.trim() + "',\n" + tmpProTypes.substring(pos, tmpProTypes.length);
let position = _js.indexOf("{"); let position = _js.indexOf("{");
let propsJs = "\nlet $namespace='" + namespace.trim() + "';\n"; let propsJs = "\nlet $namespace='" + namespace.trim() + "';\n";
@ -927,8 +927,7 @@
if (vcFramework.notNull(_header['location'])) { if (vcFramework.notNull(_header['location'])) {
window.location.href = _header['location']; window.location.href = _header['location'];
return; return;
} };
;
successCallback(res.bodyText, res); successCallback(res.bodyText, res);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -1025,8 +1024,7 @@
if (vcFramework.notNull(_header['location'])) { if (vcFramework.notNull(_header['location'])) {
window.location.href = _header['location']; window.location.href = _header['location'];
return; return;
} };
;
successCallback(res.bodyText, res); successCallback(res.bodyText, res);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -2560,4 +2558,35 @@
} }
})(window.vcFramework); })(window.vcFramework);
//解决 toFixed bug 问题
(function(vcFramework) {
Number.prototype.toFixed = function(d) {
var s = this + "";
if (!d) d = 0;
if (s.indexOf(".") == -1) s += ".";
s += new Array(d + 1).join("0");
if (new RegExp("^(-|\\+)?(\\d+(\\.\\d{0," + (d + 1) + "})?)\\d*$").test(s)) {
var s = "0" + RegExp.$2,
pm = RegExp.$1,
a = RegExp.$3.length,
b = true;
if (a == d + 2) {
a = s.match(/\d/g);
if (parseInt(a[a.length - 1]) > 4) {
for (var i = a.length - 2; i >= 0; i--) {
a[i] = parseInt(a[i]) + 1;
if (a[i] == 10) {
a[i] = 0;
b = i != 1;
} else break;
}
}
s = a.join("").replace(new RegExp("(\\d+)(\\d{" + d + "})\\d$"), "$1.$2");
}
if (b) s = s.substr(1);
return (pm + s).replace(/\.$/, "");
}
return this + "";
}
})(window.vcFramework);