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:
- [in PHP] for each product calculate extended price (it's quantity in cart multiplied by price of single product)
- [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 number||33.574999999999996|
PHP rounded version (via "sprintf"):
|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.