|
@@ -1,15 +1,14 @@
|
|
|
'use strict';
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ * 1. 必须引用decimal.min.js
|
|
|
+ * 2. 如果使用ZhCalc.mathCalcExpr和ZhCalc.tranExpr必须引用math.min.js
|
|
|
* @author Mai
|
|
|
* @date
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
-;math.config({
|
|
|
- number: 'BigNumber',
|
|
|
-});
|
|
|
+;
|
|
|
const zhBaseCalc = (function () {
|
|
|
const zeroPrecision = 12, mulPrecision = 12, divPrecision = 12;
|
|
|
|
|
@@ -71,6 +70,7 @@ const zhBaseCalc = (function () {
|
|
|
* @type {{add, sub, mul, div, round}}
|
|
|
*/
|
|
|
const ZhCalc = (function () {
|
|
|
+ let mathConfig = false;
|
|
|
Decimal.set({precision: 50, defaults: true});
|
|
|
const percentReg = /((\d+)|((\d+)(\.\d+)))%/g;
|
|
|
/**
|
|
@@ -286,7 +286,16 @@ const ZhCalc = (function () {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+ function checkMathConfig () {
|
|
|
+ if (!mathConfig) {
|
|
|
+ math && math.config({
|
|
|
+ number: 'BigNumber',
|
|
|
+ });
|
|
|
+ mathConfig = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
function mathCalcExpr(expr) {
|
|
|
+ checkMathConfig();
|
|
|
return parseFloat(math.evaluate(expr));
|
|
|
}
|
|
|
function tansExpr(expr) {
|