欧元的 PHP money_format
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16519923/
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
PHP money_format for EURO
提问by Dinuka Thilanga
We can use following code for get $ mark and format money.
我们可以使用以下代码来获取 $ 标记和格式化钱。
setlocale(LC_MONETARY, 'en_US.UTF-8');
$amount = money_format('%(#1n', $amount);
How to get euro symbol from php money_format?
如何从 php money_format 获取欧元符号?
回答by Rajeev Ranjan
i think this will work
我认为这会奏效
setlocale(LC_MONETARY, 'nl_NL.UTF-8');
$amount = money_format('%(#1n', 20);
echo $amount;
回答by Sudz
Use this
用这个
setlocale(LC_MONETARY, 'nl_NL');
$amount = money_format('%(#1n', $amount);
回答by Bashirpour
$price = 880000;
echo number_format($price, 2, ',', '.');
input => 880000
output => 880.000,00
输入 => 880000
输出 => 880.000,00
回答by Metacowboy
A quite old thread but if some google here That worked even on a local MAMP
一个相当古老的线程,但如果这里有一些谷歌即使在本地 MAMP 上也能工作
setlocale(LC_MONETARY, 'de_DE');
echo money_format(' %!n', 1.620.56);
// 1.620.56
回答by Pete - iCalculator
This is an old thread but I felt it worth sharing a relevant solution as the top answer doesn't provide an actual solution. I found this whilst searching for Spanish LC_monetary so if, like me, you end up here you know have an answer.
这是一个旧线程,但我觉得值得分享一个相关的解决方案,因为最佳答案没有提供实际的解决方案。我在搜索西班牙语 LC_monetary 时发现了这个,所以如果像我一样,你最终来到这里,你就知道有答案了。
I use the following wrapped in a function with the advantage that it handles zeros nicely (see example in calculations). I use this in my calculators for a slicker accounting layout. This example is Spain but you can use whichever Euro area you prefer:
我使用以下包裹在函数中的优点,它可以很好地处理零(请参见计算中的示例)。我在我的计算器中使用它来获得更流畅的会计布局。这个例子是西班牙,但你可以使用你喜欢的任何欧元区:
setlocale(LC_MONETARY, "en_ES");
function C_S($iv) {
if(in_array($iv, array(' ','',0)) ){return'<i>€</i>0.00';}
else{return str_replace('EU','<i>€</i>', money_format("%i", $iv));}
}
the italics are not necessary, I use them with css for alignment for finance style reports. Again, here for info.
斜体不是必需的,我将它们与 css 一起用于财务风格报告的对齐。再次,在这里获取信息。
to use:
使用:
echo C_S(1234);
回答by Muhannad A.Alhariri
You can use the HTML entity
您可以使用 HTML 实体
"&euro";
Directly in your code
直接在你的代码中
$amount = money_format('%(#1n', $amount) .htmlentities('€');
EDIT
编辑
Or you can use the !flag %(#!1n'so you code will looks like
或者你可以使用!flag %(#!1n'所以你的代码看起来像
$amount = money_format('%(#!1n', $amount) .htmlentities('€');
You can see the following post
你可以看看下面的帖子
Hope this would help
希望这会有所帮助
回答by Himanshu Saini
Finally a Italy locale worked for me.
最后一个意大利语言环境为我工作。
$amount = '1600.00';
setlocale(LC_MONETARY, 'it_IT.UTF-8');
$amount = money_format('%.2n', $amount);
echo str_replace('Eu','€',$amount);