简体   繁体   English

小数点逗号代替小数点

[英]Decimal comma instead of decimal point

How can I change a decimal point to decimal comma by setting it in php.ini without any changes in code on my local server running on Windows?如何通过在 php.ini 中设置小数点将小数点更改为小数点逗号,而无需更改在Windows 上运行的本地服务器上的代码

3.14 >> 3,14

I tried to set我试图设置

intl.default_locale = cs_CZ 

without any results.没有任何结果。

EDIT : The reason why I'm asking is that if I execute the code on hosting I get numbers with decimal comma, but when I transfer same code to my local server there is a decimal point.编辑:我问的原因是,如果我在托管上执行代码,我会得到带十进制逗号的数字,但是当我将相同的代码传输到本地服务器时,会有一个小数点。 Where is the catch?渔获在哪里?

For example - Linux hosting:例如 - Linux 托管:

echo 100 / 3; // 33,333333333333

Local server on Windows: Windows 上的本地服务器:

echo 100 / 3; // 33.333333333333

What is the reason?是什么原因?

EDIT 2 : If I use编辑 2 :如果我使用

setlocale(LC_NUMERIC, 'cs_CZ');
echo 100 / 3;

I will get the same result 33.333333333333 , so the catch must be in configuration files or in Windows itself.我将得到相同的结果33.333333333333 ,因此问题必须在配置文件或 Windows 本身中。

intl.default_locale sets the locale for intl functions only, see this comment . intl.default_locale仅为intl函数设置语言环境,请参阅此注释

If your code doesn't use an intl function for the number formatting, there's no way around changing the code.如果您的代码不使用intl函数进行数字格式设置,则无法更改代码。 It should be as easy as setting the locale for money / number formatting to Czech.它应该像将货币/数字格式的语言环境设置为捷克语一样简单。

For money:为了钱:

setlocale(LC_MONETARY, 'cs_CZ');

For numbers:对于数字:

setlocale(LC_NUMERIC, 'cs_CZ');

So what I discovered is that only way, how you can do this on Windows is:所以我发现这是唯一的方法,你如何在Windows上做到这一点:

setlocale(LC_ALL, 'czech');

Thanks to http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx感谢http://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.90%29.aspx

For linux:对于Linux:

This is a local configuration issue, probably caused after installing php-intl recently, which changed it for you unintentionally.这是一个本地配置问题,可能是最近安装了 php-intl 后无意中为您更改了它引起的。

Edit your /etc/default/locale file and change the LC_NUMERIC line to编辑您的 /etc/default/locale 文件并将 LC_NUMERIC 行更改为

LC_NUMERIC = "en_GB.UTF-8" LC_NUMERIC = "en_GB.UTF-8"

You might want to change any other setting there, then reboot.您可能想要更改那里的任何其他设置,然后重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM