Problem with inaccurate tax, discount or total value

By default CS-Cart rounds decimals to 2 digits after the decimal point. It can cause inaccuracy of the nearest tenth or hundredth of discount, tax or total prices if product price or defined tax value contain two decimal places and a large number of products is bought.

To increase precision of taxes, discounts and products prices calculation:
  1. Open the fn_common.php file located in the core directory of your CS-Cart installation.
  2. Find and replace the following part of code there:
    return sprintf("%.2f", round((double) $price + 0.00000000001, 2));

    with this one:

    return sprintf("%.4f", round((double) $price + 0.00000000001, 4));
  3. Save the file.

This will make decimals be rounded to 4 digits. It is possible to round values to a larger number of decimal places if you wish.

Noticed an error in the article or it is not clear enough? Any suggestions to improve it? Please let us know by filling in the feedback form. Click here.