ในรูปแบบtax/Sales_Total_Quote_Taxมีวิธีการ_deltaRound()ที่รอบราคา มันเพิ่มเดลต้าขนาดเล็กเพื่อหยุดพฤติกรรม nondeterministic เมื่อปัดเศษ 0.5
/**
 * Round price based on previous rounding operation delta
 *
 * @param float $price
 * @param string $rate
 * @param bool $direction price including or excluding tax
 * @param string $type
 * @return float
 */
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;
}แต่มันเก็บเดลต้า หากไม่สามารถหาเดลต้าที่เก็บไว้ได้ ทำไม? ในฐานะ tar ที่ฉันสามารถบอกได้สิ่งนี้นำไปสู่ผลลัพธ์ที่แตกต่างด้วยการทำงานที่เหมือนกัน
สมมติว่าเรามี$priceของ 3.595 $deltaและเราไม่ได้มีแคช เมื่อเราทำตามวิธีนี้เราจะได้รับ $ delta = 0.000001 จากนั้นเราจะได้รับ$price= 3.595001 ซึ่งปัดเป็น 3.60 ดังนั้นเราจึงมี$delta-0.004999 ใหม่ และเรากลับ 3.60
ยกเว้นตอนนี้เรามีเดลต้าลองทำอีกครั้งกับ$price= 3.595 $price= 3.595 - 0.004999 = 3.590001
ซึ่งถ้าเราปัดเราจะได้ 3.59 คำตอบที่ต่างกัน
สำหรับฉันแล้วดูเหมือนว่าอัลกอริทึมการปัดเศษที่ใช้อย่างน้อยควรให้คำตอบเดียวกันทุกครั้งที่มีการใช้อาร์กิวเมนต์ที่เหมือนกัน แต่ไม่ใช่ในเวลานี้
