[英]How to set currency to setlocale / money_format in PHP
setlocale
is taking a country and a language as parameters. setlocale
将国家和语言作为参数。
'money_format' is taking amount and other params. 'money_format'正在获取金额和其他参数。
But how can I tell a currency to PHP? 但是,如何将货币告知PHP?
What if I want to use EUR in Australia? 如果我想在澳大利亚使用欧元怎么办?
like javascript
can: 像javascript
一样可以:
var formatter = new Intl.NumberFormat('en-AU', {
style: 'currency',
currency: 'EUR',
});
formatter.format(2500);
Chrome
obviously understands that it is a foreign currency that need to be formatted to international currency format
like so "EUR 2,500.00"
. Chrome
显然了解它是一种外币,需要将其格式化为international currency format
例如"EUR 2,500.00"
。
IE
does not understand it, but it offers something "€2,500.00"
IE
无法理解,但提供了"€2,500.00"
PHP
(that is how I use it) PHP
(这就是我的使用方式)
setlocale(LC_MONETARY, 'en-AU');
return money_format('%.2n', 2500);
gives "$2,500.00"
(I know it is Ubuntu
should be blamed) 给出"$2,500.00"
(我知道应该归咎于Ubuntu
)
It takes some default currency for Australia and I cannot find a way to change it. 澳大利亚需要一些默认货币,我找不到改变它的方法。 Is there a formatting library or something that I'm missing that can help? 是否有格式库或我缺少的东西可以帮助您?
Java script does not require installing locales individually, like Ubuntu does. Java脚本不需要像Ubuntu一样单独安装语言环境。 Maybe should we rely on Browsers in this case? 在这种情况下,也许我们应该依靠浏览器吗?
You can use the NumberFormatter
in the intl
extension instead. 您可以在intl
扩展名中使用NumberFormatter
。
$fmt = new NumberFormatter('en_AU.UTF8', NumberFormatter::CURRENCY);
print $fmt->formatCurrency(2500, 'EUR');
And it doesn't require to install every locale individually, since it ships with its own locale data. 而且,由于它附带了自己的语言环境数据,因此不需要单独安装每个语言环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.