Browse Source

修复formatMoney方法四舍五入不准确bug

ellisran 2 months ago
parent
commit
8a19717667
3 changed files with 7 additions and 3 deletions
  1. 1 1
      app/extend/helper.js
  2. 1 1
      app/view/dashboard/workspace.ejs
  3. 5 1
      app/view/datacollect/index.ejs

+ 1 - 1
app/extend/helper.js

@@ -938,7 +938,7 @@ module.exports = {
             s = 0;
             return s.toFixed(decimal);
         }
-        s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
+        s = decimal === 0 ? parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '' : (Math.round(parseFloat((s + '').replace(/[^\d\.-]/g, '')) * Math.pow(10, decimal)) / Math.pow(10, decimal)).toFixed(decimal) + '';
         if (!decimal) {
             s += '.';
         }

+ 1 - 1
app/view/dashboard/workspace.ejs

@@ -752,7 +752,7 @@
                                         break;
                                     case 'revise':
                                         html.push(`<li class="list-group-item">
-                                            <span class="${acRevise.auditStringClass[n.status]}">${acRevise.auditString[n.status]}</span> <a href="/tender/${n.id}/revise/${n.rid}/info" target="_blank">${n.name}</a> 台账修订第${n.corder}<span class="float-right">${moment(new Date(n.shenpi_time)).format('HH:mm:ss')}</span></li>`);
+                                            <span class="${acRevise.auditStringClass[n.status]}">${acRevise.auditString[n.status]}</span> <a href="/tender/${n.id}/revise/${n.rid}/info" target="_blank">${n.name}</a> 台账修订第${n.corder}<span class="float-right">${moment(new Date(n.shenpi_time)).format('HH:mm:ss')}</span></li>`);
                                         break;
                                     case 'change':
                                         html.push(`<li class="list-group-item">

+ 5 - 1
app/view/datacollect/index.ejs

@@ -1641,6 +1641,7 @@
                 // total_checked_change_positive_price = ZhCalc.add(total_checked_change_positive_price, t.change_p_tp);
                 // total_checked_change_negative_price = ZhCalc.add(total_checked_change_negative_price, t.change_n_tp);
                 total_after_change_price = ZhCalc.add(total_after_change_price, ZhCalc.add(t.total_price, t.change_tp));
+                console.log(total_after_change_price, t.total_price, t.change_tp);
                 total_stage_price = ZhCalc.add(total_stage_price, t.end_gather_tp);
                 // total_material_price = ZhCalc.add(total_material_price, t.material_tp);
                 total_advance_price = ZhCalc.add(total_advance_price, t.advance_tp);
@@ -1988,7 +1989,10 @@
             s = 0;
             return s.toFixed(decimal);
         }
-        s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '';
+        console.log(parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '');
+        // 按decimal位数四舍五入方法
+        s = decimal === 0 ? parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(decimal) + '' : (Math.round(parseFloat((s + '').replace(/[^\d\.-]/g, '')) * Math.pow(10, decimal)) / Math.pow(10, decimal)).toFixed(decimal) + '';
+        console.log(s, Math.pow(10, decimal));
         if (!decimal) {
             s += '.';
         }