magento2: Rounding problem on prices when adding tax to display prices
Preconditions
- Magento 2.2.x, 2.3.x & 2.4-develop
- PHP 7.1.9 & 7.2
- MySql 5.6.37
Steps to reproduce
- Set Configuration > Tax > Calculation Settings to following:
- Set Configuration > Tax > Price Display Settings to Including Tax
Expected result
- Tax should be added to price set in product data when getting amount from classes extending Magento\Framework\Pricing\Price\AbstractPrice. Example Affirm Water Bottle with price of 7.00 with tax of 25 percent should result final value of 8.75
Actual result
- Magento\Framework\Pricing\Price\AbstractPrice returns value of 8.750001. This is visible example data-price-amount se to price wrapper element. See screenshot.
Own findings
Problem seems to stem from Magento\Tax\Model\Calculation\AbstractCalculator. Calculator is adding delta of 0.000001 in deltaRound to prices, even if the $round is set to false and no rounding is happening.
/**
* Round price based on previous rounding operation delta
*
* @param float $price
* @param string $rate
* @param bool $direction
* @param string $type
* @param bool $round
* @return float
*/
protected function deltaRound($price, $rate, $direction, $type = self::KEY_REGULAR_DELTA_ROUNDING, $round = true)
{
if ($price) {
$rate = (string)$rate;
$type = $type . $direction;
// initialize the delta to a small number to avoid non-deterministic behavior with rounding of 0.5
$delta = isset($this->roundingDeltas[$type][$rate]) ?
$this->roundingDeltas[$type][$rate] :
0.000001;
$price += $delta;
$roundPrice = $price;
if ($round) {
$roundPrice = $this->calculationTool->round($roundPrice);
}
$this->roundingDeltas[$type][$rate] = $price - $roundPrice;
$price = $roundPrice;
}
return $price;
}
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 4
- Comments: 34 (4 by maintainers)
Commits related to this issue
- Resolved #18025 - Rounding problem on prices when adding tax to display prices — committed to jaimin-ktpl/magento2 by jaimin-ktpl 6 years ago
Any chance to fix the issue that was reported back in 2018?
Yes, still an issue.
Hi @magento-engcom-team can you please pick up in this issue, it has been neglected for too long.