Browse Source

数字精度

master
han\hanst 3 weeks ago
parent
commit
2a79ac97a7
  1. 20
      src/views/modules/production-inbound/inboundRegister.vue

20
src/views/modules/production-inbound/inboundRegister.vue

@ -210,7 +210,11 @@ export default {
}, },
computed: { computed: {
totalQty() { totalQty() {
const sum = this.handlingUnit.reduce((sum, item) => sum + Number(item.qty), 0);
// 使
const sumInCents = this.handlingUnit.reduce((sum, item) => {
return sum + Math.round(Number(item.qty) * 100);
}, 0);
const sum = sumInCents / 100;
this.inboundItem.transQty = sum; this.inboundItem.transQty = sum;
return sum; return sum;
}, },
@ -413,9 +417,18 @@ export default {
return; return;
} }
const qtyToReceive = parseFloat(this.inboundItem.transQty) || 0;
if (qtyToReceive <= 0) {
this.$message.warning('请先输入入库数量');
return;
}
const perQtyValue = parseFloat(perQty); const perQtyValue = parseFloat(perQty);
const packageQty = Math.floor(qtyToReceive / perQtyValue); const packageQty = Math.floor(qtyToReceive / perQtyValue);
const remainder = qtyToReceive - (packageQty * perQtyValue);
// 使
const remainderInCents = Math.round(qtyToReceive * 100) - Math.round(perQtyValue * 100) * packageQty;
const remainder = remainderInCents / 100;
this.handlingUnit = []; this.handlingUnit = [];
@ -456,7 +469,8 @@ export default {
if (!perQty || !packageQty || isNaN(perQty) || isNaN(packageQty)) { if (!perQty || !packageQty || isNaN(perQty) || isNaN(packageQty)) {
return this.$message.warning("请填写有效的包装信息"); return this.$message.warning("请填写有效的包装信息");
} }
const qty = parseFloat(perQty) * parseInt(packageQty);
// 使
const qty = Math.round(parseFloat(perQty) * 100) * parseInt(packageQty) / 100;
const code = String(this.handlingUnit.length + 1); const code = String(this.handlingUnit.length + 1);
const newItem = { ...this.hanlingItem, qty, code }; const newItem = { ...this.hanlingItem, qty, code };
this.handlingUnit.push(newItem); this.handlingUnit.push(newItem);

Loading…
Cancel
Save