Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

GetSubTotal in the DefaultOrderFormCalculator is rounding up the subtotal!



We have just noticed that an Epi method called GetSubtotal within the DefaultOrderFormCalculator is returning a round up price.

The price is 18.325 and should always stay as 18.325. We do not want any rounding to happen. But when using the DefaultOrderFormCalculator the subtotal comes back as 18.33.

How do we get it to return the right amount (18.325)?

Edited, Dec 18, 2019 17:44

If you check the documentation for order form calculator (I don't have permission to add links) you you can easily overwrite to default functionality.

Why would the sub total need to have 3 decimal points though?

Dec 19, 2019 13:15

Hi Stu!

Ah just just checked it and can see they have a sample of overriding the validators thanks. What I think I need to override is the CalculateSubTotal virtual method. But it is not clear what is causing the value to round up in the GetSubTotal method (which is called within CalculateSubTotal). Any ideas?

Its 3 digits because that is what is past through via our price feed. For now we have set the price feed to send through just 2 decimal places which has solved the issue for now.

Edited, Dec 19, 2019 16:48

It rounds up because GetSubTotal returns the type Money and I believe in that type it will make sure it returns a valid value for the set currency which wouldn't ever have 3 decimal places

Dec 19, 2019 17:16

Cheers Stu. I did have a feeling it might be something to do with it changing types but didnt run any tests at the time.

Just ran a quick one:

double doubleTest = 18.325;
decimal d = (decimal)doubleTest; //Equals 18.325
Money m = new Money((decimal)doubleTest, c); //Equals 18.33

In this case they didnt want it rounding up to 18.33 which is why it was an issue. 

Edited, Dec 19, 2019 20:38

This release note might be interesting, if you are considering an upgrade to Commerce 13.
Re-work rounding strategy in calculators

Also, Quan Mai wrote some tips on tweaking the number of decimal places for a currency.
Control the rounding level of currencies

Dec 19, 2019 20:44

Thanks again Mads!

Dec 20, 2019 9:38
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.