• Resolved JapeNZ

    (@japenz)


    Hi there,
    I’ve noticed that the tax calculations seem to be off when creating an invoice with Woo 3.3.3.

    I have a product that has a total price is $8.09, when I add to an invoice the price is $7.03 plus $1.0545 tax.
    The tax is then rounded to $1.05 for a total of $8.08.
    Shouldn’t this round up to $1.06 for a total of $8.09?

    Same applies to shipping of $3.80 which is $3.3 + $0.495, should be $3.80 but is coming up as $3.79.

    The strange thing is I look on a previous invoice for the same $8.09 product and the amounts are different, they were previously $7.0348 + 1.0552 for a total of $8.09.

    Any thoughts as to what might have happened here?

    Kind regards,
    JP

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter JapeNZ

    (@japenz)

    Hello again,
    So it seems the prices excluding tax are set to two decimal places and the tax is set to 4 decimal places?
    Is this how it should be or do you think I may have a plugin or theme conflict perhaps?
    I’ve tried disabling a few plugins but figured I should check with you guys before I go ahead and disable everything.

    If it’s by design am I able to set it back to four decimal places for both?

    Thanks for your help.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    The only setting to control this by default is at WooCommerce > Settings > General : http://cld.wthms.co/fRztLp

    There are other filters / constants than can control individual decimal precision, so perhaps you have a custom snippet or plugin doing that?

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    Thanks for getting back me, the general setting just sets the front end display right?
    I’m getting the 2 decimals on the back end when creating invoices so I have to assume it’s a plugin conflict.
    Thanks for confirming this for me, I’ll work my way through the plugins and try and work out what’s causing it.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Fwiw, I believe that setting affects both frontend and backend, rounding precision all around when calculations are made.

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    Seems you’re right mate I’ve just done a test by changing the setting to 4 decimal points and the prices are now to 4 decimal places when creating an invoice.

    This must be a recent change as it wasn’t like this before, is there a way to have this set at 4 decimal places for calculations but to display at 2 decimal places?

    I’d like the calculations to be correct which requires 4 decimal places, but I don’t want to display product prices as $8.9900 rather than $8.99 on the front end.

    The currency options settings state “The following options affect how prices are displayed on the frontend”, it doesn’t mention it will also effect calculations.

    Thanks again for your help πŸ™‚

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Here are some constants you can set to alter rounding calculation: https://github.com/woocommerce/woocommerce/blob/master/includes/class-woocommerce.php#L207-L209. They’d be defined earlier in your wp-config file to change I believe.

    Can see here, that WC will mostly use whichever is higher: https://github.com/woocommerce/woocommerce/blob/64bcabf0af9a05274d53ec833a4e8c9153509bc4/includes/wc-core-functions.php#L1549-L1553. Either WC_ROUNDING_PRECISION constant, or the number of decimals you have set plus 2.

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    Thank you for this.

    So going by this:
    “Can see here, that WC will mostly use whichever is higher: https://github.com/woocommerce/woocommerce/blob/64bcabf0af9a05274d53ec833a4e8c9153509bc4/includes/wc-core-functions.php#L1549-L1553. Either WC_ROUNDING_PRECISION constant, or the number of decimals you have set plus 2.”

    It seems if I have the rounding set to 2 decimal points here WooCommerce > Settings > General : http://cld.wthms.co/fRztLp the price and tax should be calculated to 4 decimal points “decimals you have set plus 2”, and displayed with 2 decimal points.

    However as I found out by changing this setting to 4 decimal points, after which it then calculated both to four decimal points, I have to assume this isn’t working for me as it should.

    This line from https://github.com/woocommerce/woocommerce/blob/64bcabf0af9a05274d53ec833a4e8c9153509bc4/includes/wc-core-functions.php#L1549-L1553 suggests it shouldn’t be possible for it to be calculating the prices by 2 decimal points unless it’s set to 0.

    Get rounding precision for internal WC calculations.
    * Will increase the precision of wc_get_price_decimals by 2 decimals, unless WC_ROUNDING_PRECISION is set to a higher number.

    I’d really like to get this sorted if possible, any suggestions you may have will be very much appreciated.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Rounding calculations and display are two separate concepts. When you have it set to display 2 decimals places, while doing math it will be rounding all values to 4 decimal places at a minimum.

    The WC_ROUNDING_PRECISION defaults to 6, thus if you have it set to show 2 decimal places, it will actually round to 6 places when doing math in most places. You can make this value larger or smaller.

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,

    Exactly, except it’s not doing either of these.
    With the decimal places set to 2 decimal points if I add a product to an invoice the price has 2 decimal points (not 4 as there should be), and the tax has 4 decimal points as it should.

    This is causing incorrect calculations, please let me know how I can fix this.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    I don’t follow. If decimal place is set to 2, it should show two decimal places. That is what the setting does…controls the visual display.

    There are calculations happening at more precise levels though.

    I think there’s something else at play with some customizations or plugins you have that is causing some troubles with calculations.

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    Sorry I haven’t explained myself very well.

    So the decimal point setting is set to 2 places, showing product prices on the front end as $8.99 for example.

    With this setup when I previously created a customer invoice and added a $8.99 product to the invoice the price amount would be $7.8174 and the tax amount would be $1.1726 adding up to exactly $8.99. This meant I could add multiple amounts of the product with the total price being multiples of $8.99.

    Previous $8.99 Product
    Previous Multiple $8.99 Products

    Now when I create a customer invoice and add a $8.99 product the price amount is $7.82 (only 2 decimal places) which in turn makes the tax amount $1.173, adding up to $8.993.
    Meaning when multiples are added to the invoice the total is incorrect (5 x $8.993 = $44.96 rather than $44.95).

    Current $8.99 Product
    Current Multiple $8.99 Products

    While in this example the difference is only $0.01, the price amount being in only 2 decimal places when creating an invoice happens on every product I try to add.

    Can you tell me if this is how it’s now supposed to be happening please?
    If not then it might be a plugin conflict of some sort which I’ll need to resolve.

    As a workaround I’ve been manually altering the price amounts when creating invoices though its not an ideal fix.

    Thanks again for your help.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    > Can you tell me if this is how it’s now supposed to be happening please?

    If you have it set to show two decimal places, then that is how it should look on invoices and everywhere in your store. The previous behavior that you are relating to sounds like it was incorrect.

    The decimal display and decimal calculations are two different things though. Just because it is set to show only two decimal places, does not mean it only calculates with two. This would be problematic, so calculations are done at a more precise level.

    If your prices aren’t adding up, then there is definitely something else at play. Either a discounts plugin or your invoice plugin has a bug most likely.

    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    I’ve tried disabling all plugins except Woocommerce and am still getting the same result.

    I realise the decimal display and decimal calculations are two different things, however in this case they are acting the same way.

    As mentioned, with the decimal places set to 2 they are shown as 2 on the front end (which is what we want) but are also being calculated to 2 on the back end (not what we want) for purchase prices and invoices.

    If I change it to 4 decimal places the back end is calculated to 4 decimal places (which is what we want), but the front end displays to 4 places (as it should but definitely not what we want).

    I am using a discounts plugin, but have deleted it for testing purposes, I don’t have an invoicing plugin installed.

    Would you be able to do a comparative test?
    Set up a tax rate of 15.0000%
    Create a product on a test Woocommerce site with a price including tax of $8.09 then ‘add an order’ and add the $8.09 product.
    Let me know if the product total after recalculating is $8.08 (which is what I’m seeing) or $8.09.

    This way we can be certain the problem is on my site rather than Woocommerce itself.

    I’m at a loss as to what could be causing the issue, any suggestions would be very much appreciated.

    Kind regards,
    JP

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    What do you mean by “after recalculating”?

    Here is my product including tax: http://cld.wthms.co/Xe5Czs
    Cart: http://cld.wthms.co/6Kmhxe
    Checkout: http://cld.wthms.co/zlkZd1
    Order received: http://cld.wthms.co/jHdG4J
    Admin: http://cld.wthms.co/I98EOp
    Admin after hitting the recalculate button: http://cld.wthms.co/QdiEpI

    Currency settings: http://cld.wthms.co/LTMF98
    Tax settings: http://cld.wthms.co/QyeLMd

    • This reply was modified 8 years, 1 month ago by Caleb Burks.
    Thread Starter JapeNZ

    (@japenz)

    Hi Caleb,
    Thank you for doing this πŸ™‚
    So the issue is from when I manually create an order / invoice.

    Please go to Woocommerce > Orders and Add Order
    Add your $8.09 product and ‘Recalculate’.

    Here are images of what I’m currently seeing, when I hit the edit icon the product has been calculated to 2 decimals.

    Add New Order – Recalculate
    Add New Order – Total calculated to 2 decimals

    Here’s also an old older I created where the product was calculated to 4 decimals for comparison.

    Add New Order – Old order total calculated to 4 decimals

    If you can me know how it looks on your end please that would be really helpful.

    Thanks again for all your help!

    Kind regards,
    JP

    • This reply was modified 8 years, 1 month ago by JapeNZ.
    • This reply was modified 8 years, 1 month ago by JapeNZ.
Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘Tax Rounding Issue’ is closed to new replies.