php magento 价格 getPrice() 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1450865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:38:05  来源:igfitidea点击:

magento price getPrice() value

phpmagento

提问by webkul

function getDescriptionHtml($tpl, $p){
    $out = "";
    $pr = $p["product"];

    if(Mage::getStoreConfig('featuredproducts/displayoptions/title') == 'description'){
        $out .= "<ins><h4>{$pr->getName()}</h4></ins>";
    }
    $out .= "<span class=\"description\"".
            (!Mage::getStoreConfig('featuredproducts/displayoptions/description') ?
                    "style=\"display:none;\""
                :
                    ""
            )
            .">{$p['description']}</span>";
    $out .= "<ins><div>".
            (Mage::getStoreConfig('featuredproducts/displayoptions/price') ?
                    "<span style=\"font-size:45px\">{$pr->getPrice()}</span>"
                :
                    ""
            )       
            ."".
            (Mage::getStoreConfig('featuredproducts/displayoptions/bnb') ?
                    "<div><button style=\"postion:relative;margin-left:80px;margin-top:140px\" class=\"form-button\" onclick=\"setLocation('{$p["url"]}')\"><span>{$tpl->__('Buy Now')}</span></button></div>"
                :
                    "")
            ."
            </div></ins>";
    return $out;        
}

Per the code shown, when I'm using $pr->getPrice() its output looks like 299.0000, but I want it to be like 299.00. How can I do this?

根据显示的代码,当我使用 $pr->getPrice() 时,它的输出看起来像 299.0000,但我希望它像 299.00。我怎样才能做到这一点?

回答by Alan Lapington

Why not give this a try...

为什么不试试这个...

Mage::helper('core')->currency($pr->getPrice());

It gives you a currency symbol too.

它也给你一个货币符号。

回答by R T

Mage::helper('core')->currency($_product->getFinalPrice(),true,false);
  • "true" for price format.
  • "false" for no html.
  • 价格格式为“true”。
  • 没有 html 的“假”。

this i did in Magento 1.7.0.2

这是我在 Magento 1.7.0.2 中所做的

回答by Yannick Motton

Try number format

试试数字格式

"<span style=\"font-size:45px\">{" . number_format($pr->getPrice(), 2) . "}</span>"

回答by dan

or

或者

sprintf("%0.2f",$_product->getFinalPrice());

回答by Marlon Creative

Use "round" as number format doesn't always work correctly, depending on the location and currency formatting:

使用“round”作为数字格式并不总是能正常工作,具体取决于位置和货币格式:

<span style=\"font-size:45px\">{" . round($_product->getFinalPrice(),2) . "}</span>