Developer forum

Forum » Ecommerce - Standard features » Rounding of price calculations in checkout

Rounding of price calculations in checkout

Pernille Mortensen
Reply

We have a problem in one of our customers shops, where the calculation of payment fees, vat and totals are mathematically correct but looks wrong because of the rounding.

 

This is what the customer sees and what the bookkeeper has a difficult time handling:

Product: kr 15.293,00
Payment fee (1,75%): kr 267,63
Subtotal: kr 15.560,63
Vat (25%): kr 3.890,16
Total: 19.450,78 

As you can see the subtotal (15.560,63) + vat (3.890,16) should be 19.450,79 and not ,78

Matematically (when you use all decimals) the calculation is correct though:

Product: kr 15.293,00
Payment fee (1,75%): kr 267,6275
Subtotal: kr 15.560,6275
Vat (25%): kr 3.890,15688
Total: 19.450,78438 

 

This all happens because each number is rounded to 2 decimals, but the calculations are based on the full number including all decimals. I have read that that the dw database will always use as many decimals as possible and that the rounding is handled in UI.

Is there a way to change this and use the rounded numbers in the calculation?


Replies

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Pernille,

We have encountered something similar in one of our projects and we ended up storing the prices with VAT in the database.

It would work if you sell to a single country but it might prove difficult if you are selling to multiple countries (multiple VAT rates).

Our decision was for an older DW version. Maybe there is some specific functionality in newer versions to handle this situation. At this point, I am not aware of it, but the guys from DW should have the final word here.

Adrian

 
Pernille Mortensen
Reply

Thank you for your input.

I am not sure that would be a solution is this case though. We would still have two numbers with many decimals (payment fee and the vat which is calculated based on the complete amount including payment fee) that we need to add together - creating a total that might vary because of rounding.
Furthermore this client is selling b2b so using prices with vat seems wrong.

I was hoping for a functionality to handling situations like this. My guess is that several shops would encounter similar problems if they use vat and a %-fee of some kind

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Pernille,

The problem is the rounding on the VAT amount and most specifically, when the rounding occurs.

In our case it was also a B2B project. The difference is that you will always have the price with VAT as calculated by the ERP and you calculate the VAT amount based on the value with VAT. And this will avoid rounding differences.

The same can be done for shipping and payment fees.

Adrian

 
Nicolai Pedersen
Reply

Dynamicweb 9.9 contains a change in how VAT and rounding is handled - should handle the above scenario.

BR Nicolai

 
Pernille Mortensen
Reply

That sounds good! I will update and see if it fixes the problem.

Is there a new setting or something I need to enable, or is this new change just applied automatically?

 
Nicolai Pedersen
Reply

That is default behavior, so no changes needed.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

This improvement in 9.9, what does it do?

Has it changed the rounding precision?

I am asking because I have an integration with SAP and VAT calculation came into play. They have a few different VAT rates, depending on the product type and their calculations in SAP are using 8 decimals while the display is using only 2 decimals.

Would this improvement solve this calculation?

Thank you,

Adrian

 
Nicolai Pedersen
Reply

When we work with calculated prices - in Dynamicweb inside the object "CalculatedPrice" we calculate vat, quantities etc. with rounded values instead of the full value.

Instead of calculating precise numbers as before for vat and quantity multiplications and only round display values, saving the precise values to the database, values are now rounded to the currencys regional info currency decimal precision when calculated. That means for most currencies, the calculated amount is rounded to 2 decimals before we do anything with it. (In japan the precision is 5 and probably other places as well)

For example:
VAT Percent: 7%
Unit price (not rounded): 7.9€ (w/o VAT) 8.453€ (w VAT)
Unit price (rounded): 7.9€ and 8.45€
Quantity 2 (not rounded): 15.8€ and 16.906€
Quantity 2 (rounded): 15.8€ and 16.91€
 
When the customer sees 8.45€ for 1 and 16.91€ for 2, they are confused.
When rounding the total for quantity 2 to 16.90, the VAT percent would also become 6.96% instead of the 7% that it actually is.
 
So that is the change.

If you calculate in SAP using Live integration, Dynamicweb will probably not calculate anything.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the detailed explanation. All clear.

I want to detail this part: "If you calculate in SAP using Live integration,..."

Is there an existing/supported integration with SAP?

Thank you,
Adrian

 
Nicolai Pedersen
Reply

Nope... I know there are some customers on SAP, but we are not involved...

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

That was also my information. I was hoping though that something may have come up in the meantime :)

This means that if we want to use LiveIntegration with SAP, we would have to create our own "Connector" between SAP and DW.

Thank you,

Adrian

 
Nicolai Pedersen
Reply

You can create a provider for the current connector service. Or go directly from DW to SAP - eventually we will also leave the connector service and go direct (using odata or rest apis)

 

You must be logged in to post in the forum