Magento 2 calculates the price Inc tax based on 2 decimals. I managed to save the price as 4 decimals. This get's stored in the catalog_product_entity_decimal table.

The problem now is that the vat does not get calculated based on the 4 decimals but the 2.


  • Stored price: 41,275200
  • vat percentage: 9 %
  • expected price inc VAT: 44,989968 (displayed as 44,99)
  • actual price displayed 45,00 (41,28 x 1,09 = 44,9952)

How can I fix this, I want the calculations based on all the decimals (4 in my case), but still want to display prices with 2 decimals?

1 Answer 1


Create a Custom Module:

  1. Create di.xml file under {Vendor}/{CustomModule}/etc folder:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        <type name="Magento\Tax\Model\Calculation">
                <argument name="priceCurrency" xsi:type="object">{Vendor}\{CustomModule}\Model\PriceCurrency</argument>
  2. Create PriceCurrency Model Class File under {Vendor}/{CustomModule}/Model folder:

class PriceCurrency extends \Magento\Directory\Model\PriceCurrency

    const DEFAULT_PRECISION = 4;

    public function round($price)
        return round($price, self::DEFAULT_PRECISION);

    public function convertAndRound($amount, $scope = null, $currency = null, $precision = self::DEFAULT_PRECISION)
        return parent::convertAndRound($amount, $scope, $currency, $precision);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.