PHP如何获取给定语言环境的当前小数/千位分隔符 [英] php how to get the current decimal/thousand separator for a given locale
问题描述
我已经使用setlocale()函数设置了语言环境,比如说"en_US".
I've set the locale using the setlocale() function to let's say "en_US".
现在我正尝试在不使用千位分隔符的情况下格式化货币:
now I'm trying to format the currency without a thousand separator like this:
$ currency = number_format($ value,2, '.','');
$currency = number_format($value, 2, '.', '');
可以,但是有时我还有其他货币,并且我希望number_format根据使用区域设置使用正确的小数点分隔符.
that works, but sometimes I have other currencies and I want the number_format to use the correct decimal separator according to the use locale.
是否有一种方法可以根据已设置的语言环境以某种方式获取当前的十进制分隔符?
Is there a way to get the current decimal separator somehow, based on the locale that has been set?
推荐答案
localeconv()
should do it. From the manual:
返回一个关联数组 包含本地化数字和 货币格式信息.
Returns an associative array containing localized numeric and monetary formatting information.
这是语言列表在Windows上由setlocale()
识别的字符串.
Here is a list of language strings recognized by setlocale()
on Windows.
这篇关于PHP如何获取给定语言环境的当前小数/千位分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!