Browse Source

四舍五入调整

MaiXinRong 6 years ago
parent
commit
72c8237b7e
2 changed files with 4 additions and 2 deletions
  1. 2 1
      app/extend/helper.js
  2. 2 1
      app/public/js/zh_calc.js

+ 2 - 1
app/extend/helper.js

@@ -14,6 +14,7 @@ const streamToArray = require('stream-to-array');
 const _ = require('lodash');
 const bc = require('../lib/base_calc.js');
 const Decimal = require('decimal.js');
+Decimal.set({precision: 50, defaults: true});
 
 module.exports = {
     _: _,
@@ -645,7 +646,7 @@ module.exports = {
      */
     round(value, decimal) {
         //return value ? bc.round(value, decimal) : null;
-        return value ? Decimal.round(value, decimal).toNumber() : null;
+        return value ? new Decimal(value).toDecimalPlaces(decimal).toNumber() : null;
     },
     /**
      * 汇总

+ 2 - 1
app/public/js/zh_calc.js

@@ -57,6 +57,7 @@
  * @type {{add, sub, mul, div, round}}
  */
 const ZhCalc = (function () {
+    Decimal.set({precision: 50, defaults: true});
     /**
      * 加法 num1 + num2
      * @param num1
@@ -104,7 +105,7 @@ const ZhCalc = (function () {
      * @returns {*}
      */
     function round(value, decimal) {
-        return value ? Decimal.round(value, decimal).toNumber() : null;
+        return value ? new Decimal(value).toDecimalPlaces(decimal).toNumber() : null;
     };
     return {add, sub, mul, div, round}
 })();