Post by interstellar » Tue Jan 08, 2019 11:59 pm

Dear I have a rounding problem in my opencart 3.0.2. I have an order. In opencart this order have a total of 149.10 € but the correct total is 149.12 (i have repeat this total in excel and with my manual calculator).
I noticed this problem because I have acquired an extension that connect my opecart to a invoice program and this rounding error generate a problem in the invoice program because the total is not correct and the order is not passed to the invoice.

How I resolve? Is a bug of opencart?

Thank's a lot

Newbie

Posts

Joined
Tue Jan 08, 2019 11:47 pm

Post by ADD Creative » Wed Jan 09, 2019 5:53 am

It could be due to OpenCart using 4 decimal places for the prices. All calculations are done and then converted to the number of decimal places for display.

What are your exact product prices and cart totals?

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by kestas » Wed Jan 09, 2019 6:38 am

Computers use binary numbers because they’re faster at dealing with those, and because for most calculations, a tiny error in the 17th decimal place doesn’t matter at all since the numbers you work with aren’t round (or that precise) anyway.
you can read more about that here: https://floating-point-gui.de/basic/

Custom OpenCart modules and solutions. You can write PM with additional questions... Extensions you can find here


Active Member

Posts

Joined
Tue Oct 12, 2010 2:23 am

Post by paulfeakins » Wed Jan 09, 2019 6:13 pm

interstellar wrote:
Tue Jan 08, 2019 11:59 pm
Dear I have a rounding problem in my opencart 3.0.2. I have an order. In opencart this order have a total of 149.10 € but the correct total is 149.12 (i have repeat this total in excel and with my manual calculator).
I'm not sure the other answers are right as this is a big error.

Can you provide detailed steps to replicate? What is the price of the product? What is the tax class? What percentage? Are any offers applied etc. etc.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by sfsf99 » Mon Jan 28, 2019 3:53 am

I have the same problems and I am a programmer.

I see that amounts included vat added are not the same as amounts without vat added + total vat. Sometimes 1 cent or other currency difference.

The problem is that all amounts are rounded on its own and shown after on the webpage (checkout or cart).

There is no such relation as the total = subtotal rounded + tax rounded, but all is rounded on its own, so total, subtotal and tax and mostly these all are together related as total = subtotal + tax, so not always.

My customer e.g. don't want to see vat for his customers on the website (only on the invoice) and then you see this problems (maybe it can't be avoided). Ok I can added all amounts included vat and compare to the end total of OpenCart, if I see a difference of 1 cent, I can compensate that on the first product (e.g. to correct that subtotal with 1 cent, but still strange for a customer). My customer says do it in that way and is right after, nobody sees .. in the footer we have text that there are differences because of rounding ..

New member

Posts

Joined
Thu Jan 11, 2018 5:22 am

Post by sfsf99 » Sat Feb 02, 2019 8:09 pm

Today a very simple example, I haven't seen this in previous versions of OC, so I think (but I see this later in the programs when I compare) it is an OC 3 problem.

Without vat prices :

product = 12.3960
shipping = 6.8181

With vat (21%):

product = 15
subtotal 12.40 (without vat)
shipping 6.82 (without vat)
vat = 4.04
total = 23.25

If vat was 4.03 then correct, but if all is rounded on its own without relations, you get all these problems (I had already 2, but in most cases it is correct)

New member

Posts

Joined
Thu Jan 11, 2018 5:22 am

Post by ADD Creative » Mon Feb 04, 2019 5:34 am

In a clean install of OpenCart 3.0.2.0 I get the VAT of 4.03. Have you made any modifications or installed any extensions that could affect it?

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by sfsf99 » Wed Feb 13, 2019 3:23 am

Thanks Creative, I go to try that also in a clean version and to compare what have been modified ..but even in a clean version I can't imagine if it is always correct with the rounding methods, but we will see .. I am very curious now ..

New member

Posts

Joined
Thu Jan 11, 2018 5:22 am

Post by ADD Creative » Wed Feb 13, 2019 7:24 pm

No, it won't always be correct. As the calculations are done with higher precision than what's displayed, there is always a chance of a rounding error.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by sfsf99 » Tue Mar 26, 2019 3:23 am

Yes Creative, in a new installation I get also 4.03 .. later I go to find out why that difference, maybe an extension .. I will come back on this topic for a satisfied answer :) ...

New member

Posts

Joined
Thu Jan 11, 2018 5:22 am

Post by letxobnav » Tue Mar 26, 2019 8:21 am

you have to round all values to the same decimal digits before you perform any calculations with them or you will have rounding differences afterwards.

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by dghale » Mon Nov 29, 2021 3:35 pm

Hello, i also have rounding issue on opencart. The total in opencart and total in paypal is different with decimal that's why paypal is giving invalid total amount error message. According to my analysis the item total amount is rounding after adding up all products total price instead of rounded total price of item. Please, help.

Newbie

Posts

Joined
Mon Nov 29, 2021 3:31 pm

Post by ADD Creative » Mon Nov 29, 2021 5:58 pm

dghale wrote:
Mon Nov 29, 2021 3:35 pm
Hello, i also have rounding issue on opencart. The total in opencart and total in paypal is different with decimal that's why paypal is giving invalid total amount error message. According to my analysis the item total amount is rounding after adding up all products total price instead of rounded total price of item. Please, help.
What version of OpenCart? Which PayPal payment extension are you using? What is the exact wording of the error message form PayPal?

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by dghale » Mon Nov 29, 2021 6:03 pm

ADD Creative wrote:
Mon Nov 29, 2021 5:58 pm
dghale wrote:
Mon Nov 29, 2021 3:35 pm
Hello, i also have rounding issue on opencart. The total in opencart and total in paypal is different with decimal that's why paypal is giving invalid total amount error message. According to my analysis the item total amount is rounding after adding up all products total price instead of rounded total price of item. Please, help.
What version of OpenCart? Which PayPal payment extension are you using? What is the exact wording of the error message form PayPal?
I am using Opencart Version 1.5.6.4 and Paypal Express extension. Error: 10426 - Item total is invalid.

Newbie

Posts

Joined
Mon Nov 29, 2021 3:31 pm

Post by ADD Creative » Mon Nov 29, 2021 11:44 pm

dghale wrote:
Mon Nov 29, 2021 6:03 pm
I am using Opencart Version 1.5.6.4 and Paypal Express extension. Error: 10426 - Item total is invalid.
What currencies are you using and what do you have Decimal Places set to for each of them. They can't be more than 2 and some will need to be 0.

https://www.paypal.com/us/smarthelp/art ... 426-ts2049

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom
Who is online

Users browsing this forum: alanjones, DesignCart and 80 guests