Skip to content

Commit

Permalink
#491 second attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
jstaerk committed Oct 4, 2024
1 parent 36c6546 commit 6dcf7f5
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public LineCalculator(IZUGFeRDExportableItem currentItem) {
BigDecimal vatPercent = currentItem.getProduct().getVATPercent();
if (vatPercent == null)
vatPercent = BigDecimal.ZERO;
BigDecimal multiplicator = vatPercent.divide(BigDecimal.valueOf(100), RoundingMode.HALF_UP);
BigDecimal multiplicator = vatPercent.divide(BigDecimal.valueOf(100));
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
price = priceGross.subtract(allowance).add(charge);
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity(), RoundingMode.HALF_UP)
.subtract(allowanceItemTotal).setScale(2, RoundingMode.HALF_UP);
itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator);

Expand Down

1 comment on commit 6dcf7f5

@langfr
Copy link
Contributor

@langfr langfr commented on 6dcf7f5 Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge of my PR #497 still required.
This approach generates a new error, line 43/44 should read as

itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity(), MathContext.DECIMAL128).subtract(allowanceItemTotal).setScale(2, RoundingMode.HALF_UP);

as commented yesterday on the previous commit.
Division is done with high precision, without exception, and only the result is rounded to 2 decimal places.

Please sign in to comment.