ID: 41246 Updated by: [EMAIL PROTECTED] Reported By: phil at goli dot at Status: Bogus Bug Type: ICONV related Operating System: Linux Gentoo PHP Version: 5.2.1 New Comment:
Did you actually read my command lines? It shows that PHP automatically converts floats to the locale's display format when they're converted to strings. It has nothing to to with utf8_convert() and is expected bahaviour. <quote url="http://de2.php.net/manual/en/language.types.string.php#language.types.string.casting"> An integer or a floating point number (float) is converted to a string representing the number with its digits (including the exponent part for floating point numbers). Note: The decimal point character is defined in the script's locale (category LC_NUMERIC). See setlocale(). </quote> Previous Comments: ------------------------------------------------------------------------ [2007-05-01 14:20:41] phil at goli dot at sorry for bothering but i'm quite sure there's something wrong. do you have locales installed on your machine? your code php -r 'setlocale(LC_ALL,"de_DE"); echo 10.01,"\n";' doesn't use utf8_encode which causes the problem together (and ONLY if locale de_DE is really installed on your system) with setlocale(LC_ALL,"de_DE"). so it doesn't prove that this is not a bug. please try these two lines: $loc_de = setlocale(LC_ALL,"de_DE"); echo 'Example only works if locale de_DE is installed! Current locale: "' . $loc_de . '". Output: ' . (utf8_encode(0.01) + 0.01) . "<br>"; Summary: a string that comes out of utf8_encode is not automatically type casted to float when adding another float to it (this would normally happen if you don't us utf8_encode). but this whole scenario is only the case if setlocale(LC_ALL,"de_DE") is used! ------------------------------------------------------------------------ [2007-05-01 13:19:20] [EMAIL PROTECTED] 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 [EMAIL PROTECTED]:~$ php -r 'echo 10.01,"\n";' 10.01 [EMAIL PROTECTED]:~$ php -r 'setlocale(LC_ALL,"de_DE"); echo 10.01,"\n";' 10,01 ------------------------------------------------------------------------ [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, '[EMAIL PROTECTED]', '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, '[EMAIL PROTECTED]', '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 "[EMAIL PROTECTED]" 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 "[EMAIL PROTECTED]" 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
