question

rizwan avatar image
rizwan asked rachel Deactivated answered

how to calculate exact discount in clover.

hello all,

clover round discount to next decimal number.

for example

i have one line item with price 0.85$. and i am applying 10% discount on each line item in order.

discount amount is 0.09$ but we expecting it 0.085$. 

now if i add one more same line item in order then total order amount goes to 1.70$

this time total discount amount is 0.18$ which should be 0.17$ and we are also expecting total discount to 0.17$

i am using the same code provided by clover.

    Discount discount1 = new  Discount();  
   discount1.setName(discountValue + "% Discount");
  discount1.setPercentage(discountValue);

whereas discount object only accept long type in setPercentage Method

    for (LineItem updatedLineItem : updatedLineItems) {
     orderConnector.addLineItemDiscount(orderId, updatedLineItem.getId(), discount1);
     }

can we modify discount amount without round to next decimal number ??

any help would be appreciated.

Orders
10 |2000

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

1 Answer

rachel avatar image
rachel Deactivated answered

Hi @Rizwan,

Per our docs, when rounding decimal amounts smaller than the cent, fives will be rounded up, and each discount (or tax rate) is rounded before it's added to another.

10 |2000

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

Welcome to the
Clover Developer Community