Results 1 to 10 of 12

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Posts
    71
    Plugin Contributions
    0

    Default [OPEN CHANGE-358]Products with specials price can cause rounding error in order total

    Hello,

    Im having an annoying issue with calculating tax...

    Basically if I use this as an example...

    Shipping: €3.94
    Subtotal: €55.37
    Tax 18%: €10.68

    Total: €69.99

    The Shipping and subtotal needs the 18% added which to me works out at 10.67

    Now how come the shop is rounding it up to 10.68, On the calculator is shows... 10.6758 so im guessing this is the reason why its rounding up.

    Is there a way to stop this, and ONLY read the 2 digits after the decimal point without rounding it up

    Thank you
    Sam

  2. #2
    Join Date
    Jun 2003
    Posts
    33,720
    Plugin Contributions
    0

    Default Re: Tax Calculation rounding up??

    What version of Zen Cart? How many items were in the cart and what are their prices?
    Please do not PM for support issues: a private solution doesn't benefit the community.

    Be careful with unsolicited advice via email or PM - Make sure the person you are talking to is a reliable source.

  3. #3
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: Tax Calculation rounding up??

    Same problem in a 1.3.9h install.

    See image at frnt dot org / tax-rounding dot gif

    The issue must have existed for some time. It is only now that a customer pointed out the error.

    I did a comparison of the relevant files (original 1.3.9h install files vs live install) and cannot find a flaw.

    Frank

  4. #4
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: Tax Calculation rounding up??

    I should add that this product is part of a sale.

    Original price $28.95 (inc tax)
    discount 5% = $1.45
    sale price $27.50 (inc tax)

    see product page

  5. #5
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: Tax Calculation rounding up??

    After digging through the DB I established that both (products_price and final_price) are stored with 4 decimals, in my example 25.0023 (excl tax) derived from 27.5025 (inc 10% tax) and rounded from 25.0022727272


    original product price $28.95 (inc tax)
    discount 5% = $1.45 which in the background is calculated as 1.4475
    sale price $27.50 (inc tax) visible to customer but calculates as 27.5025


    this is the result of 28.95 - 1.4475 = 27.5025

    on the invoice this is displayed at Price (inc) = $27.50

    now the order contains say 7 items, the customer expects $27.50 x 7 = $192.50 but gets charged $27.5025 x 7 = $192.5175 which rounds to $192.52

    It seems that these calculations are using a function that always uses 4 decimals. If that function (which I still need to find) is changed to 2 decimals then the problem IMHO should be solved ... ??

  6. #6
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Re: Tax Calculation rounding up??

    Found it!

    In includes/functions/functions_prices.php around lines 94-107 there are 5 instances of

    Code:
    return number_format($blah_blah, 4, '.', '');
    set to 4 decimals. Changed these to 2 and replicated the order from my previous example.

    Bingo!

    As the customer I was charged exactly $192.50 and not $192.52

    In the DB table orders_products both (products_price and final_price) are now found as 25.0000 and not as 25.0023 (excl tax)

    The calculation is now performed without fractions of cents which seems to have caused the error.

  7. #7
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,378
    Plugin Contributions
    9

    Default Products with specials price can cause rounding errors in order total

    The following applies to v 1.3.9x and 1.5, not sure about earlier versions:

    In includes/functions/functions_prices.php around lines 94-107 there are 5 instances of

    return number_format($blah_blah, 4, '.', '');
    set to 4 decimals.

    Depending on the specials price of a given product this can cause fractions of cents which add up to one or several cents being added to the order total (products price x qty)

    Changing the decimals to 2 eliminates the error.

    For further explanation see posts #3-6 above.

  8. #8
    Join Date
    May 2011
    Posts
    89
    Plugin Contributions
    0

    Default Re: Products with specials price can cause rounding errors in order total

    i also have this problem with my 1.3.9h version. we did fixed up rounding from items on special but this happened today: customer purchased an item on sale and paid local tax. when this two numbers add up its 1 penny more from what it should be. as a result we cant import this order into our quickbooks. But when person purchases 2 items on sale without paying local tax this rounding problem is not happening, all adds up smooth.

 

 

Similar Threads

  1. v150 [OPEN CHANGE-323]rounding error with attributes and salemaker
    By lankeeyankee in forum Bug Reports
    Replies: 9
    Last Post: 4 Jan 2013, 06:30 PM
  2. can I calculate the shipping price by order total price?
    By linjuming in forum General Questions
    Replies: 2
    Last Post: 26 Aug 2012, 02:28 PM
  3. v150 Specials Based On Total Order Price
    By israelimports in forum Setting Up Specials and SaleMaker
    Replies: 1
    Last Post: 18 Feb 2012, 12:51 PM
  4. Specials Price Rounding...
    By Alex Clarke in forum General Questions
    Replies: 8
    Last Post: 29 Oct 2006, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg