# question

## Tax calculation mismatch issues

Hi, we have been experiencing some issues related to tax calculation with clover orders. We have followed the guide provided on for Working With Orders by Clover.

```public Price getTax(Collection<? extends LineItem> lines) {
long taxTotalInCents = 0;
Decimal orderLevelDiscountMultiplier = getDiscountMultiplier();

for (LineItem lineItem : lines) {
long itemTaxTotal;
long itemVal = lineItem.getPrice().getCents() * lineItem.getUnitQuantity().longValue();
long itemDiscountTotal = 0;
if (lineItem.getAmountDiscount() != null) {
itemDiscountTotal += lineItem.getAmountDiscount().getCents();
}
if (lineItem.getPercentDiscounts() != null) {
long percentageDiscountTotal = lineItem.getPercentDiscounts().stream().mapToLong(value -> (itemVal * value.multiply(100000).longValue())).sum();
itemDiscountTotal += percentageDiscountTotal;
}
long itemTotalAfterDiscounts = itemVal - itemDiscountTotal;
long itemTotalAfterAllDiscounts = orderLevelDiscountMultiplier.multiply(itemTotalAfterDiscounts).longValue();
itemTaxTotal = lineItem.getTaxRates().stream().mapToLong(taxRate -> (itemTotalAfterAllDiscounts * taxRate.getRate().multiply(100000).longValue())).sum();
taxTotalInCents += itemTaxTotal;
}

BigDecimal taxTotalRoundVal = BigDecimal.valueOf(taxTotalInCents).divide(new BigDecimal(10000000), RoundingMode.HALF_UP);

return new Price(taxTotalRoundVal.longValue());
}```

This is the method we're utilizing to calculate the tax for the line items.

We're seeing discrepancies for tax values calculated by us and what's displayed on Clover Orders/Register apps, and it's mostly 1 cent over or under.

Example:
Item Price - \$1.87
Tax Elements - 8.25% and 5%

Tax Total from our Calculations - \$0.248 -> After Round Half Up - \$0.25
Tax Total from Clover Orders/Register App - \$0.24

Please assist in figuring out the best approach to calculate the taxes for line items. A guide on how tax calculations are handled on Clover end would be really helpful. Because we have to tally the amounts we charge to the values displayed on Clover end, else the order either gets overcharged by 1 cent or gets undercharged and they go on to Partially-Paid status.

TIA.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I think the issue is that you aren't rounding after calculating each individual tax. For example, if I do this:

```>>> round(1.87 * .0825 + 1.87 * .05, 2)
0.25
```

There's your \$.25. However this is wrong. You have to round the result of the tax calculation for each tax. This is what you should be doing:

```>>> round(1.87 * .0825, 2) + round(1.87 * .05, 2)
0.24```

Think of it this way. You can't give a tax authority partial cents. So when you calculate 8.25%, it has to be a transactable currency amount. Ultimately that's what the merchant is doing. Taking the taxes for each authority and writing a check (so to speak).

Also see Jacob Abrams's really excellent post on this topic:
https://community.clover.com/questions/15679/rounding-is-not-behaving-consistently.html

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @Jeffrey Blattman, we tried to implement this and to verify we ran the values against the Clover Register app and yet we're still seeing some issues.

Scenario is as follows.

Tax - 6%

Item One - 12.95

Item Two - 5.95

Item Three - 3.95

When items are added separately, the taxes are calculated as below.

Item One - 0.78

Item Two - 0.36

Item Three - 0.24

Total Tax - 1.38

Yet, when we add all three items to the same order, we get the Tax total as 1.37 in the Register app.

Why is this? What is this discrepancy?

0 Likes 0 · ·
Nimila Hiranya

@Jacob Abrams Any help with this would be highly appreciated.

0 Likes 0 · ·

Okay, found the clarification required on Function for calculating total tax of an order.

Share

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.