Thread: double rounding

Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2009
    Posts
    15
    Plugin Contributions
    0

    Default double rounding

    I had a problem with a price being rounded incorrectly. The webshop I have should have prices ending on 0 or 5 (so 1.00, 1.05, 1.10, etc).

    The tax rate is 19%, so if I have a price without taxes of 37.605, than to me the price including taxes is:

    37.605 * 1.19 = 44.74995 => 44.75

    However zen-cart 1.3.8 comes with 44.74 because it does some strange rounding. To zen-car the price including taxes is:

    zen_round(37.605,2) + zen_round(37.605 * 0.19,2) =
    36.6 + 7.14 = 44.74

    The I do not understand when 37.605 is rounded to 37.6. The numbert of decimals (scale) is set to 2, so it should have rounded to 37.61.

    If I execute "round(37.605,2)" directly, I still get 37.6... This is wierd, PHP per default does "round half up".

  2. #2
    Join Date
    Mar 2009
    Posts
    15
    Plugin Contributions
    0

    Default Re: double rounding

    I have replaced the round($number, $precision) with

    $t = ($number * pow(10,$precision)) + 0.5;
    $t = (int)("" . $t);
    $t = $t / pow(10,$precision);

    And now the outcome is correct.

  3. #3
    Join Date
    Mar 2009
    Posts
    15
    Plugin Contributions
    0

    Default Re: double rounding

    Appearantly this is semicorrect behavior

    http://www.experts-exchange.com/Web_..._23201889.html

    The number simply isn't accurate enough for this specific number.

    However, I would then move to suggest that zencart should not use PHP's round function and use one of the alternatives suggested in the link. (Or my replacement hack.)

  4. #4
    Join Date
    Mar 2009
    Posts
    15
    Plugin Contributions
    0

    Default rounding error

    http://www.zen-cart.com/forum/showthread.php?p=702001

    If a products has price 37.605 then this is rounded in 2 decimals to 37.60 instead of 37.61. PHP's round function does not handle floats very well.

    http://www.experts-exchange.com/Web_..._23201889.html

    Zencart should use a better rounding function as explained in the link above.

 

 

Similar Threads

  1. v151 Price Rounding
    By rebel tech in forum General Questions
    Replies: 4
    Last Post: 22 Jan 2013, 06:23 PM
  2. v151 Price rounding
    By rebel tech in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 2 Dec 2012, 05:27 PM
  3. Tax rounding
    By pietpetoors in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 0
    Last Post: 28 Nov 2012, 10:31 AM
  4. Rounding up and rounding down how to stop this?
    By Kazz in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 9
    Last Post: 24 Jul 2008, 06:40 PM

Bookmarks

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
Zen-Cart, Internet Selling Services, Klamath Falls, OR