我在Magento中遇到了一個奇怪的四捨五入問題。我的產品設置爲 *產品價格含20%增值稅爲183.59Magento稅收四捨五入問題
我在購物籃中添加了30件商品,價格爲30 * 183.59 = 5507.70。我可以在購物籃/結帳中看到這個值,所以沒關係。如果我在籃子裏只有一件物品,那就沒問題。
而且最終的增值稅將是5507.70 *一百二十零分之二十〇= 917.95,但我越來越918.00
你有任何想法如何解決這個問題或者我會看看?提前致謝。
我在Magento中遇到了一個奇怪的四捨五入問題。我的產品設置爲 *產品價格含20%增值稅爲183.59Magento稅收四捨五入問題
我在購物籃中添加了30件商品,價格爲30 * 183.59 = 5507.70。我可以在購物籃/結帳中看到這個值,所以沒關係。如果我在籃子裏只有一件物品,那就沒問題。
而且最終的增值稅將是5507.70 *一百二十零分之二十〇= 917.95,但我越來越918.00
你有任何想法如何解決這個問題或者我會看看?提前致謝。
最後我找到了解決方案。我改變了系統>增值稅>稅收計算方法基於從單價到行總計,它的工作,更多細節here
我發現的問題是在core/store
模型。我不得不重寫roundPrice
方法並改變那裏的舍入精度。
public function roundPrice($price)
{
return round($price, 4);
}
一輪的價格在Magento根據以往的整操作三角洲。
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;
}
有時,這可以導致錯誤由於高delta計算誤差($this->_calculator->round($price)
)。例如,由於這個原因,一些價格可以在±1分的範圍內變化。
要避免這種情況,您需要提高增量計算的準確性。
變化
$this->_roundingDeltas[$type][$rate] = $price - $this->_calculator->round($price);
到
$this->_roundingDeltas[$type][$rate] = $price - round($price, 4);
的變化需要在這兩個文件來進行:
app/code/core/Mage/Tax/Model/Sales/Total/Quote/Tax.php:1392 app/code/core/Mage/Tax/Model/Sales/Total/Quote/Subtotal.php:719
請勿修改或破解核心文件!重寫!
該解決方案在不同版本的Magento 1.9.x上進行了測試,但也許這可以在早期版本中使用。
更改roundPrice
函數,如下所示,可以解決舍入誤差問題,但可能會導致其他問題(例如,某些平臺需要四捨五入至小數點後兩位)。
public function roundPrice($price)
{
return round($price, 4);
}
重寫絕對不是一個合適的解決方案!對你有好處,但它會導致PayPal支付問題(有效訂單退貨標記爲「可疑欺詐」)。當你使用這個重寫時要小心! – simonthesorcerer
是的,我同意。改變四捨五入將我們的問題固定在一個地方,但在另一個地方打破了它。我認爲在所有情況下都有完美的解決方案基本上是不可能的。 – Jaro
我終於成功解決了一些與te官方知識庫條目有關的問題:http://www.magentocommerce.com/knowledge-base/entry/magento-ce-18-ee-113-tax-calc – simonthesorcerer