We are aware of several rounding issues within the core Magento tax module that cover scenarios that have been described. Presently we're working on those issues for an upcoming 1.13 release. Those rounding issues are triggering a simple Paypal check that determines if the line items in the cart add up correctly. It looks like Fabian's patch takes care of the Paypal check in the short term.
If you have any questions, comments, or suggestions on how we can improve the Magento Tax module please don't hesitate to contact me as I'm the product manager responsible for taxes.
Regards,
Chuck
Info
Round price in Magento based on previous rounding operation delta.
app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392
app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php:719
protected function _deltaRound($price, $rate, $direction, $type = 'regular')
{
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;
$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
$price = $this->_calculator->round($price);
}
return $price;
}
Sometimes this can cause an error due to the high delta calculation error ($this->_calculator->round($price)
). For example, for this reason, some prices can vary in the range of ±1 cent.
Solution
To avoid this, you need to improve the accuracy of the delta calculation.
Change
$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
to
$this->_roundingDeltas[$type][$rate] = $price - round($price, 4);
Changes need to be made in both files:
app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392
app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php:719
Don't modify or hack core files! Do a rewrite!
The solution was tested on different versions of Magento 1.9.x, but maybe this will work in earlier versions.
P.S.
Change roundPrice
function, as shown below, can solve the rounding error problem, but it can cause others (for example, some platforms require rounding up to 2 decimal places).
app/code/core/Mage/Core/Model/Store.php:995
public function roundPrice($price)
{
return round($price, 4);
}
Best Answer
Not a direct fix to solve your problem, but this should be solved in the CE 1.8 release that is expexted at the end of this month,
From http://www.magentocommerce.com/knowledge-base/entry/ce-18-later-release-notes:
Rounding Error Fixes
The following issues relate to one-cent rounding errors in the web store or shopping cart: