|
@@ -9,6 +9,9 @@
|
|
|
*/
|
|
|
|
|
|
const math = require('mathjs');
|
|
|
+math.config({
|
|
|
+ number: 'BigNumber',
|
|
|
+});
|
|
|
const PayConst = require('../const/deal_pay.js');
|
|
|
const payType = PayConst.payType;
|
|
|
const deadlineType = PayConst.deadlineType;
|
|
@@ -72,7 +75,12 @@ class PayCalculate {
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
- const value = math.eval(formula);
|
|
|
+ // 使用mathjs计算 math.eval('17259401.95*0.9') = 15533461.754999999,正确应为 15533461.755
|
|
|
+ // const value = math.eval(formula);
|
|
|
+ // 使用逆波兰法四则运算,可防止出现误差,但是只支持四则运算,不支持科学运算
|
|
|
+ // const value = this.ctx.helper.calcExprStrRpn(formula);
|
|
|
+ // 使用mathjs的大数运算,可支持所有
|
|
|
+ const value = parseFloat(math.eval(formula));
|
|
|
return value;
|
|
|
} catch(err) {
|
|
|
return 0;
|
|
@@ -92,7 +100,12 @@ class PayCalculate {
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
|
- const value = math.eval(formula);
|
|
|
+ // 使用mathjs计算 math.eval('17259401.95*0.9') = 15533461.754999999,正确应为 15533461.755
|
|
|
+ // const value = math.eval(formula);
|
|
|
+ // 使用逆波兰法四则运算,可防止出现误差,但是只支持四则运算,不支持科学运算
|
|
|
+ // const value = this.ctx.helper.calcExprStrRpn(formula);
|
|
|
+ // 使用mathjs的大数运算,可支持所有
|
|
|
+ const value = parseFloat(math.eval(formula));
|
|
|
return value;
|
|
|
} catch(err) {
|
|
|
return 0;
|