#41246 [Opn->Bgs]: Setting locales to german and applying utf8_encode to a float messes it up.
| From: | mike@php.net | Date: | Tue, 01 May 2007 13:19:20 +0000 |
| Subject: | #41246 [Opn->Bgs]: Setting locales to german and applying utf8_encode to a float messes it up. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-112137@lists.php.net to get a copy of this message | ||
ID: 41246
Updated by: mike@php.net
Reported By: phil at goli dot at
-Status: Open
+Status: Bogus
Bug Type: ICONV related
Operating System: Linux Gentoo
PHP Version: 5.2.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
mike@honeybadger:~$ php -r 'echo 10.01,"\n";'
10.01
mike@honeybadger:~$ php -r 'setlocale(LC_ALL,"de_DE"); echo
10.01,"\n";'
10,01
Previous Comments:
------------------------------------------------------------------------
[2007-05-01 00:00:37] phil at goli dot at
Description:
------------
Applies to PHP versions 4.4.1, 4.4.4, 5.2.1, etc.
1. setlocales to german:
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
2. assign a float to a variable by defining a string: $myTest =
'10.01';
3. add a float to that string: $myTest = $myTest + 0.01;
4. convert that float to utf8:
$myTest = utf8_encode($myTest);
5. add another float to that utf8 string: $myTest = $myTest + 0.01;
6. if the german locales are installed on the system then the output
will be wrong. utf8_encode chops off the positions after decimal
point.
Reproduce code:
---------------
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
echo '<html><body><form><textarea cols="40"
rows="40">';
echo 'Preferred locale for german on this system is "' . $loc_de .
'"' . "\n";
echo 'Example only works if locales for german are installed!' .
"\n\n";
echo 'Normal:' . "\n";
$myTest = '10.01'; var_dump($myTest);
$myTest = $myTest + 0.01; var_dump($myTest);
// no utf8_encode
$myTest = $myTest + 0.01;
echo 'Result should be 10.03 and it is: ';
var_dump($myTest);
echo "\n\n" . 'With utf8_encode:' . "\n";
$myTest = '10.01'; var_dump($myTest);
$myTest = $myTest + 0.01; var_dump($myTest);
$myTest = utf8_encode($myTest); var_dump($myTest);
$myTest = $myTest + 0.01;
echo 'Result should be 10.03 BUT it is: '; var_dump($myTest);
echo '</textarea></form></body></html>';
exit;
Expected result:
----------------
Preferred locale for german on this system is "de_DE@euro"
Example only works if locales for german are installed!
Normal:
string(5) "10.01"
float(10,02)
Result should be 10.03 and it is: float(10,03)
With utf8_encode:
string(5) "10.01"
float(10,02)
string(5) "10,02"
Result should be 10.03 ... and it is: float(10,03)
Actual result:
--------------
Preferred locale for german on this system is "de_DE@euro"
Example only works if locales for german are installed!
Normal:
string(5) "10.01"
float(10,02)
Result should be 10.03 and it is: float(10,03)
With utf8_encode:
string(5) "10.01"
float(10,02)
string(5) "10,02"
Result should be 10.03 ... and it is: float(10,01)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41246&edit=1