question

rmgas avatar image
rmgas asked Miguel Deactivated commented

Rounding discrepancies

I've read the documents and other posts here but I'm still not coming up with spot on amounts

Suppose I've got an order and do the following for each line item:

1.) Get item price
2.) Subtract any line item level discount percentages
3.) Subtract discount line item discount amounts
4.) Subtract any order level discount percentages (proportionally)
5.) Subtract any order level discount amounts
6.) Multiply by tax rate to get tax.

Out of this, I store the result from each calculation in a Java class object.

Once I've done this for all line items, I loop through my objects and add up the net amount and the tax amount. At this point right before I write my final result to the database, I round.

In a good number of my orders, I am 1 penny off either in the total or the total tax.

Just to make sure I understand, Clover only rounds at the very end of the process, right? Line item level detail data is left in raw unrounded form. Is this the way it should be or should I be rounding with each calculation? I seem to match most of the time when I don't round until the end but for the life of me I cannot figure why I have a significant number of records that are a penny off.

Thanks in advance!

TaxesDiscounts
3 comments
10 |2000

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

Miguel avatar image Miguel commented ·

Are there multiple tax rates or just one?

0 Likes 0 ·
rmgas avatar image rmgas commented ·
Just one.
0 Likes 0 ·
Miguel avatar image Miguel rmgas commented ·

@rmgas, can you provide an example? Either the line items, discounts, prices, and tax rate or if you have an example on Clover provide the merchantId and orderId.

0 Likes 0 ·

0 Answers

Welcome to the
Clover Developer Community