我试图以4个小数的价格显示所有价格(我知道有点怪异,但客户要求这一点)。我已经覆盖了Mage/Core/Store,更改了Zend Lib中的Currency.php精度,并调整了Mage_directory_model_currency。

在后端,我所有的价格都正确显示,但是在前端,我收到的价格为2个小数,然后是00。尤其是层的价格非常重要。

由于我对价格没有任何知识,因此我在Magento论坛上尝试了一些教程,但没有成功。我还尝试了2次不运气的扩展。

有帮助吗?

有帮助吗?

解决方案 3

我决定不这样做,并建议客户不要推动它,因为我无法获得任何确切的结果。如评论中提到的:

4小数点精度在Magento中本质上不精确。

其他提示

我想您会在 format 内部方法 app/code/core/Mage/Directory/Model/Currency.php.

/**
 * Format price to currency format
 *
 * @param   double $price
 * @param   bool $includeContainer
 * @return  string
 */
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
{
    return $this->formatPrecision($price, 2, $options, $includeContainer, $addBrackets);
}

我必须完全重写模板的 price.phtml 无论如何,我用了
<?php printf("$%.2f", $_finalPrice) ?> 所以你可以做同样的事情,但是 %.4f

另外,如果需要对浮子进行比较,我建议:
if( abs($_price1 - $_price2) < .0001 ) 代替 if($_price1 == $_price2)

有时,PHP的类型灵活性会引起意外错误,因此通常需要向您所需的数据类型进行明确的铸造: $margin=(float)1-$margin; 我到达了我什至不尝试将多个数学操作堆叠到一行代码中的地方。

许可以下: CC-BY-SA归因
scroll top