php how to get the current decimal/thousand separa

2019-02-22 04:52发布

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, '.', '');

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?

3条回答
贼婆χ
2楼-- · 2019-02-22 05:10

It is not the best, but it works:

$locale_info = localeconv();
echo 'decimal_point=', $locale_info['decimal_point'], '<br/>/n';

localeconv() returns an associative array with other fields besides the decimal point character.

查看更多
甜甜的少女心
3楼-- · 2019-02-22 05:27

Sean Bright is right, use localeconv() function. Are you sure that you set a correct locale for your OS, because Unix-based OS use "en_US.UTF-8" like notation, while Windows use "en-US".

查看更多
迷人小祖宗
4楼-- · 2019-02-22 05:32

localeconv() should do it. From the manual:

Returns an associative array containing localized numeric and monetary formatting information.

Here is a list of language strings recognized by setlocale() on Windows.

查看更多
登录 后发表回答