ソースを参照

fix: 修复金额比较时浮点数精度问题

liujt 4 ヶ月 前
コミット
cc0602bc32

+ 2 - 2
src/views/contractManage/contractBook/components/addDialog.vue

@@ -1965,14 +1965,14 @@
           
           if(+ratioSum == 100) {
             const difference = payAmount - receiptPaymentListSum;
-            if (Math.abs(difference) > 0 && commitData.receiptPaymentList.length > 0) {
+            if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
               const lastIndex = commitData.receiptPaymentList.length - 1;
               commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
               receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
             }
           }
 
-          if(Math.abs(+receiptPaymentListSum - payAmount) > 0){
+          if(Math.abs(+receiptPaymentListSum - payAmount) > 0.01){
             this.$message.error('计划收款金额合计与优惠后金额不一致');
             return;
           }

+ 2 - 2
src/views/purchasingManage/purchaseOrder/components/addDialogNew.vue

@@ -2169,14 +2169,14 @@
           
           if(+ratioSum == 100) {
             const difference = payAmount - receiptPaymentListSum;
-            if (Math.abs(difference) > 0 && commitData.receiptPaymentList.length > 0) {
+            if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
               const lastIndex = commitData.receiptPaymentList.length - 1;
               commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
               receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
             }
           }
 
-          if(Math.abs(+receiptPaymentListSum - payAmount) > 0){
+          if(Math.abs(+receiptPaymentListSum - payAmount) > 0.01){
             this.$message.error('计划收款金额合计与优惠后金额不一致');
             return;
           }

+ 4 - 2
src/views/saleManage/saleOrder/components/addDialogNew.vue

@@ -1937,14 +1937,16 @@
             
             if(+ratioSum == 100) {
               const difference = payAmount - receiptPaymentListSum;
-              if (Math.abs(difference) > 0 && commitData.receiptPaymentList.length > 0) {
+              if (Math.abs(difference) > 0.01 && commitData.receiptPaymentList.length > 0) {
                 const lastIndex = commitData.receiptPaymentList.length - 1;
                 commitData.receiptPaymentList[lastIndex].price = (+commitData.receiptPaymentList[lastIndex].price + difference).toFixed(2);
                 receiptPaymentListSum = commitData.receiptPaymentList.reduce((acc, cur) => acc + +cur.price, 0);
               }
             }
 
-            if(Math.abs(+receiptPaymentListSum - payAmount) > 0){
+            console.log('receiptPaymentListSum~~~', +receiptPaymentListSum, payAmount);
+
+            if(Math.abs(+receiptPaymentListSum - payAmount) > 0.01){
               this.$message.error('计划收款金额合计与优惠后金额不一致');
               return;
             }