News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Rounding error in basket (joomla v153, VM v1.1.2)

Started by Goober, July 10, 2008, 20:11:53 PM

Previous topic - Next topic

Goober

Hi,

Getting a rounding error in bascket. See image for details.



Thanks
/Goober


jjk

When trying to solve this problem you may also have a look at this, which is a similar one. (copied from one of my earlier posts)
------------------
Not shure yet, but I think this problem is related to the variable jos_vm_product_price and its setting in the mysql table.

It is set to the total number of 12 digits (the precision) and the number of 5 digits after the decimal point (the scale). Don't know where the rounding to two digits takes place - in MySQL or VM?

If I type a product price (Gross) of 198.00 into the product information form, VM displays 166.38655 (VAT set to 19 percent) for the product price (Net). The last digit (5) is rounded - the numbers behind it are truncated. When I save this price, VM obviously recalculates the Gross price and changes my 198.00 to 197,99999 in the product information form, which is the result of taking the Net product price including its five digits after the decimal point x 1.19.
The 197,9999 has annoyed me for quite a while already although I didn't complain about it yet. Would be nice if I could see 198.00 in the administration product information form some time in the future. ;D

MySQL changed the handling of Decimal Data Types in MySQL 5.03
. Maybe this is causing the output described in the first post of this thread. (http://forum.virtuemart.net/index.php?topic=40053.msg126313#msg126313
-------------------

Solution: Reduce rounding to TWO decimal places


Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations


jjk

Quote from: aravot on July 19, 2008, 19:37:21 PM
Price rounding was increased because of bulk order...

Ok - I understand the point and the VM Team certainly has one more happy shop owner. But from the business point of view it is a crazy calculation, because this shop owner will probably never sell i.e. 11 units for 6.5 cent each.

Anyway - I just figured out how to set the rounding precision back to 2 decimal places. It pleases my mind better when I see the correct gross price in the product form. ;)

Now, just for the fun of i:D concerning the $0.065 unit price which was the reason for changing the rounding decimals to 5:
I have a neighbour selling stainless steel screws, but when I recently asked him for 10 screws in order to fix something, he almost kicked me out of his shop and rejected to sell them to me, because he thought his profit - maybe 25 percent of $0.065 (unit price) x 10 screws - was too small to get up from his chair. His minimum order is 1000 units.


Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

aravot

It doesn't make a difference for 10 units, it makes different for 1000 units.

1000 x 0.065 = 65 (with 5 place rounding)
1000 x 0.065 = 70 (with 2 place rounding)

Maybe we need to set rounding in product level, a Global option and a Product level which overwrites the Global option.


jjk

My "Solution" to set the rounding precision back to 2 decimal places only worked at a first glance.
While entering more products into VM 1.1.1, rounding errors showed up at certain price tags again.

I had changed the files
'product.product_form.php'
line 1345 to show
...doRound(grossValue, 2);[original value is 5]
line 1362 to show
...doRound(netValue, 2);
---------------------------
'product.product_price_form.php'
line 179 to show
...doRound(grossValue, 2);
line 194 to show
...doRound(netValue, 2);
-------------------------------
Also in phpMyAdmin, I had set
jos_vm_product_price
product_price to 'decimal(12,2)
----------------------------------

While this gives me a 2 decimal gross price (retail price) in the administration product form and initially eliminated some rounding errors, it produces wrong (rounded) gross prices in the frontent and backend for other prices. Example: In the image below 161.99 should actually read 162.00, which is the gross price I entered into the product form.

Perhaps one of the solutions I found on the MySql website can help to overcome rounding problems. (scroll down the page until you see the comments)
http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html

[attachment cleanup by admin]
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations