Skip to content

Commit

Permalink
fixed issue related to division of big decimals. issue #2681
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 26, 2024
1 parent 52e6c61 commit 437343d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ You should also get your employer (if you work as a programmer) or school,
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -2232,11 +2233,11 @@ private StyledCalculationTable getInvoicePositionsAsTable(String language) {
}

if (this.chkTaxes.isSelected()) {
BigDecimal taxForPosition = (u.multiply(up).multiply(t.divide(BigDecimal.valueOf(100f))));
BigDecimal taxForPosition = (u.multiply(up).multiply(t.divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN)));
taxRateToTaxTotal.put(t, taxRateToTaxTotal.get(t).add(taxForPosition));
totalTax = totalTax.add(taxForPosition);
}
total = total.add(u.multiply(up).multiply(BigDecimal.ONE.add(t.divide(BigDecimal.valueOf(100f)))));
total = total.add(u.multiply(up).multiply(BigDecimal.ONE.add(t.divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN))));

totalNet = totalNet.add(u.multiply(up));

Expand Down Expand Up @@ -2385,8 +2386,8 @@ public void updateTotals(InvoicePositionEntryPanel ep) {

totalNet = totalNet.add(u.multiply(up));
if (this.chkTaxes.isSelected()) {
totalTax = totalTax.add(u.multiply(up).multiply(t.divide(BigDecimal.valueOf(100f))));
totalGross = totalGross.add(u.multiply(up).multiply(BigDecimal.ONE.add(t.divide(BigDecimal.valueOf(100f)))));
totalTax = totalTax.add(u.multiply(up).multiply(t.divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN)));
totalGross = totalGross.add(u.multiply(up).multiply(BigDecimal.ONE.add(t.divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN))));
} else {
totalGross = totalGross.add(u.multiply(up));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ You should also get your employer (if you work as a programmer) or school,
import com.jdimension.jlawyer.services.JLawyerServiceLocator;
import java.awt.Component;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -1332,7 +1333,7 @@ public void updateTotals(TimesheetPositionEntryPanel ep) {
TimesheetPosition pos = tspep.getEntry();

total = total.add(pos.getTotal());
totalTax = totalTax.add(pos.getTotal().multiply(pos.getTaxRate().divide(BigDecimal.valueOf(100f))));
totalTax = totalTax.add(pos.getTotal().multiply(pos.getTaxRate().divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN)));

}
this.lblTimesheetTotal.setText(cf.format(total));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ public static String invoiceToHTML(ZUGFeRDInvoiceImporter zii) throws Exception
BigDecimal total = price.multiply(quantity);

BigDecimal tax = item.getProduct().getVATPercent();
BigDecimal taxAmount = total.multiply(tax).divide(BigDecimal.valueOf(100));
BigDecimal taxAmount = total.multiply(tax).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_EVEN);

totalTaxAmount = totalTaxAmount.add(taxAmount);
totalAmount = totalAmount.add(total);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
Expand Down Expand Up @@ -847,7 +848,7 @@ public BigDecimal calculateTotal(int intervalMinutes) {
double roundedMinutes = Math.ceil(totalMinutes / intervalMinutes) * intervalMinutes;
float roundedMinutesFloat = new Float(roundedMinutes);
if (!this.unitPrice.equals(BigDecimal.ZERO)) {
positionTotal = this.unitPrice.multiply(BigDecimal.valueOf(roundedMinutes).divide(BigDecimal.valueOf(60d)));
positionTotal = this.unitPrice.multiply(BigDecimal.valueOf(roundedMinutes).divide(BigDecimal.valueOf(60d), 2, RoundingMode.HALF_EVEN));
}
}
return positionTotal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@
import com.jdimension.jlawyer.server.utils.StringUtils;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -5136,7 +5137,7 @@ private void updateInvoiceTotal(String invoiceId) throws Exception {
BigDecimal newTotalGross = BigDecimal.ZERO;
for (InvoicePosition p : positions) {
newTotalNet = newTotalNet.add(p.getTotal());
newTotalGross = newTotalGross.add(p.getTotal().multiply((BigDecimal.ONE.add(p.getTaxRate().divide(BigDecimal.valueOf(100f))))));
newTotalGross = newTotalGross.add(p.getTotal().multiply((BigDecimal.ONE.add(p.getTaxRate().divide(BigDecimal.valueOf(100f), 2, RoundingMode.HALF_EVEN)))));
}
invoice.setTotal(newTotalNet);
invoice.setTotalGross(newTotalGross);
Expand Down Expand Up @@ -5683,7 +5684,7 @@ private float getTimesheetPercentageDone(Timesheet ts) {
for(TimesheetPosition p: positions) {
currentTotal=currentTotal.add(p.calculateTotal(ts.getInterval()));
}
return currentTotal.divide(ts.getLimit()).multiply(BigDecimal.valueOf(100f)).floatValue();
return currentTotal.divide(ts.getLimit(), 2, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(100f)).floatValue();

}

Expand Down

0 comments on commit 437343d

Please sign in to comment.