Magento – Magento 2 tax calculation

magento2productstax

I'm totaly stuck on the tax calculation (-bug?).

In Magento my Products are excluded taxes and the calculation is based on the total. So included taxes my Product has a price , let's say 15.
My taxrate is 19%

So excluding taxes I have 15 / 1,19 = 12.6050.
Since Magento is rounding these prices I added a price (excl Tax) of 12.61 to the Product.
When calculating the taxes this results in 15.01 because of the rounding thing.
When using 12.60 I still have the issue because the result is 14,99.

From what I can the the priceCurrency method already performs a round($price, 4) which should work. As far I figured out this was an issue in Magento 1.x.

How can I get 15€ including Tax, with a taxrate of 19%?

Same goes for a price like 45€. and it gets even more frustrating when a product is bought in a greater quantity

Best Answer

This has been a bug since ever due to ... well let's not talk about that. Anyway, in Magento 1.x I just had to search for all places rounding is done and raise the precision to 4 instead 2. Searching over the Magento 2 code you will probably have to do the same. I.e. upon a quick search I find this suspicious code in app/code/Magento/Directory/Model/PriceCurrency.php

    /**
     * Round price
     *
     * @param float $price
     * @return float
     */
    public function round($price)
    {
        return round($price, 2);
    }

Update: For Magento 2 you have to do it in serveral other places like templates too. It works to some degree but introduces bugs with rounding as well. Like when calculating discounts and so on. So beware.

Related Topic