php 以当前语言环境和货币格式化价格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6730180/
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-26 01:06:01  来源:igfitidea点击:

Format price in the current locale and currency

phpmagento

提问by Bizboss

I use :

我用 :

$product->getPrice();

to get the unformatted price that I can calculate "quantity X price" with ajax.

获得我可以用ajax计算“数量X价格”的未格式化价格。

I want to reformat the total in the current locale and currency. How can I do that?

我想以当前的语言环境和货币重新格式化总数。我怎样才能做到这一点?

回答by Simon

I think Google could have answered your question ;-) See http://blog.chapagain.com.np/magento-format-price/.

我认为 Google 可以回答您的问题;-) 请参阅http://blog.chapagain.com.np/magento-format-price/

You can do it with

你可以用

$formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);

回答by Silas Palmer

$formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false);

回答by Shadoweb

For formatting the price in another currency than the current one:

要以当前货币以外的另一种货币格式化价格:

Mage::app()->getLocale()->currency('EUR')->toCurrency($price);

回答by Xman Classical

By this code for formating price in product list

通过此代码在产品列表中形成价格

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

回答by Max Popoff

Unformatted and formatted:

未格式化和格式化:

$price = $product->getPrice();
$formatted = Mage::helper('core')->currency($price, true, false);

Or use:

或使用:

Mage::helper('core')->formatPrice($price, true);

回答by hex4

try this:

尝试这个:

<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>

回答by Neeraj Sharma

This is a charming answer. Work well on any currency which is selected for store.

这是一个迷人的答案。适用于为商店选择的任何货币。

$formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);