Browse Source

修改四舍五入方法

olym 7 years ago
parent
commit
a10f31e5e9
2 changed files with 7 additions and 6 deletions
  1. 6 5
      modules/glj/models/glj_list_model.js
  2. 1 1
      public/scMathUtil.js

+ 6 - 5
modules/glj/models/glj_list_model.js

@@ -16,6 +16,7 @@ import STDGLJLibGLJListModel from "../../common/std/std_glj_lib_glj_list_model";
 import MixRatioModel from "./mix_ratio_model";
 import GljModel from "../../complementary_glj_lib/models/gljModel";
 const ProjectModel = require('../../pm/models/project_model').project;
+const scMathUtil = require('../../../public/scMathUtil').getUtil();
 
 class GLJListModel extends BaseModel {
 
@@ -130,7 +131,7 @@ class GLJListModel extends BaseModel {
                 for (let tmp of mixRatioList) {
                     totalComposition[tmp.connect_code] = totalComposition[tmp.connect_code] === undefined ? tmp.consumption :
                         totalComposition[tmp.connect_code] + tmp.consumption;
-                    totalComposition[tmp.connect_code] = Number(totalComposition[tmp.connect_code].toFixed(4));
+                    totalComposition[tmp.connect_code] = scMathUtil.roundTo(totalComposition[tmp.connect_code], -4);
 
                     if (mixRatioData[tmp.glj_id] !== undefined) {
                         mixRatioData[tmp.glj_id].push(tmp);
@@ -204,18 +205,18 @@ class GLJListModel extends BaseModel {
             glj.quantity = quantityList[projectGljId] !== undefined ? quantityList[projectGljId] : 0;
             glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
             glj.quantity = compositionConsumption[gljId] !== undefined ?  glj.quantity + compositionConsumption[gljId] : glj.quantity;
-            glj.quantity = parseFloat(glj.quantity).toFixed(3);
+            glj.quantity = scMathUtil.roundTo(parseFloat(glj.quantity), -3);
 
             // 组成物数据
             gljList[index].ratio_data = mixRatioData[gljId] !== undefined ? mixRatioData[gljId] : [];
 
-            glj.unit_price.base_price = parseFloat(glj.unit_price.base_price).toFixed(2);
-            glj.unit_price.market_price = parseFloat(glj.unit_price.market_price).toFixed(2);
+            glj.unit_price.base_price = scMathUtil.roundTo(parseFloat(glj.unit_price.base_price), -2);
+            glj.unit_price.market_price = scMathUtil.roundTo(parseFloat(glj.unit_price.market_price), -2);
             // 计算调整基价
             switch (glj.unit_price.type + '') {
                 // 人工: 调整基价=基价单价*调整系数
                 case GLJTypeConst.LABOUR:
-                    glj.adjust_price = parseFloat(glj.adjustment * glj.unit_price.base_price).toFixed(2);
+                    glj.adjust_price = scMathUtil.roundTo(parseFloat(glj.adjustment * glj.unit_price.base_price), -2);
                     break;
                 // 机械类型的算法
                 case GLJTypeConst.MACHINE:

+ 1 - 1
public/scMathUtil.js

@@ -4,7 +4,7 @@
 const fs = require('fs');
 let scMath = null;
 
-getScMathUtil = function() {
+let getScMathUtil = function() {
     if (!(scMath)) {
         let data = fs.readFileSync(__dirname + '/web/scMathUtil.js', 'utf8', 'r');
         //console.log(data);