GetSubTotal in the DefaultOrderFormCalculator is rounding up the subtotal!

Vote:
 

Hi,

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)?

#211155
Edited, Dec 19, 2019 10:17
Vote:
 

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?

#211191
Dec 19, 2019 13:15
Vote:
 

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.

#211198
Edited, Dec 19, 2019 16:50
Vote:
 

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

#211200
Dec 19, 2019 17:16
Vote:
 

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. 

#211202
Edited, Dec 19, 2019 20:44
Vote:
 

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

#211203
Dec 19, 2019 20:44
Vote:
 

Thanks again Mads!

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