|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-05-07 14:02 UTC] jonathan at tricolon dot com
If I set my locale to Dutch in my php-script that converts currencies for a Dutch site, I noticed that also the internal representation of floats change as well. In Europe an amount of tenthousand dollars is written as follows: $10.000,00 unlike the USA $10,000.00 So if I set the locale to "nl_NL" the internal representation of a float with a point to seperate the integer part from the decimals (for example: $amount = 68.123) is changed to a representation of a comma ','. I would like to see it changed because it messes up calculations and the different locale settings should (IMHO) apply only to output function and such. Thanks, Jonathan PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 16:00:02 2025 UTC |
This bug seems to be still available. ?t least i can reproduce it with 4.3.0RC2 on Windows 2000 with locale set to 'ru'. <?php setlocale (LC_ALL, 'en'); echo ('1.123'*'5').'<br>'; echo ('1,123'*'5').'<br>'; setlocale (LC_ALL, 'ru'); echo ('1.123'*'5').'<br>'; echo ('1,123'*'5').'<br>'; ?> Results are: 5.615 5 5 5,615I also ran across this problem and have been messing with it for like 3 days before i finally ran across this post. If you do not consider it a bug I would recommend you at least include it in the documentation and make it very clear that you cannot perform calculations using thousands-seperators based on the locale settings. If you have a look at the following sample you can see that user-inputs will get totally messed up in case they use thousand-seperators. <? setlocale(LC_NUMERIC, "en_US") ; // setting the numeric locale to us-conventions setlocale(LC_MONETARY, "en_US") ; // setting the monetary locale to us-conventions $locale_info = localeconv(); echo "mon_decimal_point: {$locale_info["mon_decimal_point"]}<br>"; // displays the monetary decimal point used for the locale echo "mon_thousands_sep: {$locale_info["mon_thousands_sep"]}<br>"; // displays the monetary thousands seperator used for the locale echo "decimal_point: {$locale_info["decimal_point"]}<br>"; // displays the decimal point used for the locale echo "thousands_sep: {$locale_info["thousands_sep"]}<br>"; // displays the thousands seperator used for the locale // defines 2 variables that should be 1000000 and 750000 $a = "1,000,000"; $b = "750,000"; print "A = $a<br>"; print "B = $b<br>"; // performing a simple calculation that illustrates how PHP handles the numbers print "A * 1 = " . ($a*1) . "<br>"; print "B * 1 = " . ($b*1) . "<br>"; ?> Imho there is no point in having locale settings for currencies and numeric values if you cannot use it for doing calculations. Thanks /MartinHaving the setlocale function in string.c execute if ((lc.decimal_point)[0] != '.') { /* set locale back to C */ setlocale(LC_NUMERIC, "C"); } is not a solution. The particular "fix" broke other things. In many countries, comma is used as a decimal separator. Case in point: 3 weeks ago, a certain financial database of a major telco company in Europe was upgraded to use PHP 4.3.8 (formerly 4.2.2). The system uses Oracle for persistence, where the decimal separator is a comma, as is a custom in that country. So numbers came in from Oracle, and then PHP was unable to process them correctly. For example, if a client had a debt of 25,12?, and the client paid 5?, then the comparison ($paid_amount > $debt) said incorrectly that the paid amount was more than the debt. Result: hundreds of wasted man-hours. In the end we recompiled PHP without that "fix".