Child pages
  • [in-commerce] Incorrect order SubTotal after discount/coupon is applied [5.2.2-B1]
Skip to end of metadata
Go to start of metadata

The SubTotal is total price of all products added to cart (without shipping and taxes) after discounts and coupons were applied. Internally it works like this:

  1. [in PHP] for each product calculate extended price (it's quantity in cart multiplied by price of single product)
  2. [in MySQL] apply discount/coupon on each product's extended price, that was calculated before

Part of calculations are done in MySQL to speed up calculation process. Unfortunately MySQL returns resulting price with 15 digit precision compared to 4 digit precision used in PHP, which confuses PHP to the level, that affects how number rounding operations are made.


MySQL returned number33.574999999999996

PHP rounded version (via "sprintf"): 

33.57 (incorrect)
PHP rounded version (via "round"): 33.58 (correct)
MySQL rounded version (via "ROUND")33.58 (correct)

The "sprintf" is used in PHP, which allows to spot the error.


Round price on MySQL side before using it in PHP.

Related Tasks

MINC-132 - Getting issue details... STATUS