🔥 Just Launched! Werra Premium Template for HyväSee it in Action

Solution: Call to Undefined Function bccomp() in Magento 2

By Kishor ChhuganiUpdated on Jan 02, 2025 2 min read

Are you facing the call to undefined function bccomp() in Magento 2? Recently, I faced the same error while working on a client’s site.

Here, I am sharing the solution that worked for me.

Magento is an open-source e-commerce platform written in Php language. It requires a supported version of Php along with several libraries to function properly. One such required Php extension is the BCMath.

Magento uses various functions of BCMath Php extension at various steps.

For example, the bccomp() function compares the values of two long numbers during add-to-cart. In case the BCMath extension is missing, all those features may get affected.

In the present case, the customer was not able to add a product to the cart. On checking the error log of Magento 2 I found the following:

Call to undefined function MagentoInventorySalesModelIsProductSalableForRequestedQtyConditionbccomp()

Feel relaxed! I got a 100% working solution to this.

How to Fix Call to Undefined Function bccomp() in Magento 2?

The error clearly interprets that Magento 2 is not able to find the bccomp() function. This can be because the BCMath extension is either disabled or not installed in Php.

The BCMath extension may go missing because of multiple reasons, such as after the Php version upgrade or the Magento version upgrade.

The solution is simple: Enable the Php BCMath extension in the setup!

For Local Server

If you’re facing the Call to Undefined Function bccomp() in Magento 2 local installation, follow these steps to enable the BCMath Php extension:

  • Open the XAMPP Control Panel, and go to Configure > PHP in the Apache module.
  • In the Php.ini file, search for extension=php_bcmath.dll, remove ; before it and save the file.
  • Restart the server.

For Live Server

You’ll need to contact the respective hosting provider to enable the BCMath Php extension in your setup. If you’re a root user, you can also use the following command to do that:

sudo apt install php7.2-bcmath

Remember to tweak the Php version in the above command as per the configuration.

& that’s it…

Enabling the BCMath Php extension in will solve the Call to Undefined Function bccomp() in Magento 2.

The add-to-cart function on the front end will start working normally again.

If you think this solution has helped you, rate it five stars and share it on social media….!

Feel free to comment down your thoughts..

Thank You!

Kishor Chhugani Full Image
Article byKishor Chhugani

He is a Magento developer at Meetanshi with a jolly, extrovert, & friendly personality. He loves playing cricket and is a passionate foodie!