Php 如何在magento中获取自定义价格格式(精度为3)
希望有人能帮忙 需要数字_格式来显示此…上的3位小数。。。。(实际上是2)Php 如何在magento中获取自定义价格格式(精度为3),php,magento,number-formatting,Php,Magento,Number Formatting,希望有人能帮忙 需要数字_格式来显示此…上的3位小数。。。。(实际上是2) 通常使用数字格式($值,3,“,”,“),但不知道如何使其工作。您可以使用 试着用这个 echo number_format($_value, '2', '.', ',') 或 另外,请检查 更多信息: 希望这一定会对你有所帮助 [magento]\app\code\core\Mage\Checkout\Helper\Data.php 添加以下功能 public function customformatPric
通常使用数字格式($值,3,“,”,“),但不知道如何使其工作。您可以使用
试着用这个
echo number_format($_value, '2', '.', ',')
或
另外,请检查
更多信息:
希望这一定会对你有所帮助
[magento]\app\code\core\Mage\Checkout\Helper\Data.php
添加以下功能
public function customformatPrice($price)
{
return $this->getQuote()->getStore()->customformatPrice($price);
}
在[magento]\app\code\core\Mage\core\Model\Store.php中添加以下函数
public function customformatPrice($price, $includeContainer = true)
{
if ($this->getCurrentCurrency()) {
//sets the floating point precision to 3 points
return $this->getCurrentCurrency()->format($price, array('precision'=>3), $includeContainer);
}
return $price;
}
你可以像这样使用上面的代码
//magento default call
echo Mage::helper('checkout')->formatPrice(3000.1231);//Rs3,000.12
echo "<br>";
//customized function call
echo Mage::helper('checkout')->customformatPrice(3000.12313);//Rs3,000.123
//magento默认调用
echo Mage::helper('checkout')->formatPrice(3000.1231)//RS3000.12
回声“
”;
//自定义函数调用
echo Mage::helper('checkout')->customformatPrice(3000.12313)//RS3000.123
实际上,您可以直接修改[magento]\app\code\core\Mage\core\Model\Store.php中的formatPrice(),但由于您需要这两种格式,我们创建了自定义函数
希望这对您有所帮助打开[magento]\app\code\core\Mage\core\Model\Store.php
public function formatPrice($price, $includeContainer = true)
{
if ($this->getCurrentCurrency()) {
//sets the floating point precision to 3 points
return $this->getCurrentCurrency()->format($price, array('precision'=>3), $includeContainer);
}
return $price;
}
注意:-更改数组('precision'=>3)而不是数组()我知道这一点,但这不是我的问题。我如何显示为3位小数感谢uuse数字格式功能否则我必须更改mage lib文件中的货币我认为这会起作用,但在这里没有帮助。我在购物车/结帐页面上使用此方法将formatPrice($\u item->getCalculationPrice()与我的自定义属性(请参阅我的上述代码)进行分割。我使用此分割功能的唯一方法是使用此方法。仅此,我需要在所有其他情况下显示3位小数。我需要2位小数。仅此而已;)我强烈建议人们不要更改核心文件,这是一种不好的做法,然后阻止你升级你的Magento!
//magento default call
echo Mage::helper('checkout')->formatPrice(3000.1231);//Rs3,000.12
echo "<br>";
//customized function call
echo Mage::helper('checkout')->customformatPrice(3000.12313);//Rs3,000.123
public function formatPrice($price, $includeContainer = true)
{
if ($this->getCurrentCurrency()) {
//sets the floating point precision to 3 points
return $this->getCurrentCurrency()->format($price, array('precision'=>3), $includeContainer);
}
return $price;
}