|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-01 13:19 UTC] mike@php.net
[2007-05-01 14:20 UTC] phil at goli dot at
[2007-05-01 14:48 UTC] mike@php.net
[2007-05-01 15:25 UTC] phil at goli dot at
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
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)