我试图获得一个项目的正常价格,包括使用增值税:
$unitPrice = round($item->getPrice(), 2);
它给了我一个.01
的差异。
我也试过没有四舍五入-仍然.01
的差异。对于价格16.05
,它返回16.06
或16.04
。
知道我做错了什么吗?
通常在Magento中,您使用内置的货币格式方法而不是PHP的round
,例如:
$unitPrice = Mage::helper('core')->formatPrice($item->getPrice(), false); // $50.00
这将返回显示价格,如$50.00
。如果你只想要原始值,用这个代替:
$unitPrice = Mage::app()->getStore()->roundPrice($item->getPrice()); // 50.0
请注意,Mage_Core_Model_Store::roundPrice
本质上只是对你已经做的事情的一个包装,但是使用它更安全,因为它被捆绑在Magento框架中。
还有——你没有提到你使用的Magento版本,但如果低于1.8,你可能会看到这里提到的增量四舍五入问题。