Changing Rounding of Discounts

Vote:
 

Hi

This is in reference to an old topic :

world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2018/6/changing-rounding-of-discounts/

Here, it was mentioned that a possible solution will be made available in Commerce 12.4 and I do see below in Release notes :

https://world.episerver.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=COM-7335

Per the above solution, it says the rounding at the end should take care of the cent discrepancy.

However, i'm working with Commerce 12.17.2 and I'm still noticing the cent discrepancy. What I observe is the rounding only happens away from 0, for examples, if a discount is 10.405, its rounded to 10.40, whereas if its 10.455, its rounded to 10.46. This is causing a conflict.

See an example below that applies 10% discount on order, but becasue one of the lineitem totals after discount suffers from above, it ends up causing a 1 cent discrepancy between order subtotal and sum of lineitem subtotals :

Please advice if there is a way to handle this? Can we override how Epi rounds discount amounts?

#217556
Feb 25, 2020 17:24
Vote:
 

One correction here :

It looks like the promo engine might be returning decent discount amounts with/without rounding, but the ILineItemExtension.GetExtendedPrice method is actually rounding off the values.

So in DB, i can see the ExtendedPrice on LineItem as 49.455. But when I call above extension method, I get 49.46. And that trips my calculations.

As a workaround, instead of calling Epi's GetExtendedPrice method, I'm doing those calculations on my end, and instead of rounding, using Math.Floor, to get only upto 2 decimal spaces :

var entrydisc = Model.LineItem.GetDiscountTotal(ServiceLocator.Current.GetInstance<ICurrencyService>().GetCurrentCurrency());
var calcExtPrice = (Model.LineItem.PlacedPrice * Model.LineItem.Quantity) - entrydisc;
var extPrice = Math.Floor(calcExtPrice * 100)/100;

This gives me 49.45 as the extended price for 49.455.

Please tell me if there is a better workaround for this?

#217560
Feb 25, 2020 20:06
Vote:
 

Hi Ritu,

After investigated your case, I found that it's a issue.

The 10% discount amount is $18.835 then it be rounded to $18.84 but when calculating tho total of order, the order discount amount does not rounded, it's still keep is $18.835 then the Total = 188.35 - 18.835 = 169.515 after that, it will be rounded to $169.52.

I'll create a bug for this case.

You can overwrite the GetTotal(IOrderGroup) of IOrderGroupCalculator to implement in your own.

#217815
Mar 02, 2020 7:32
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.