From: phil at goli dot at Operating system: Linux Gentoo PHP version: 5.2.1 PHP Bug Type: ICONV related Bug description: Setting locales to german and applying utf8_encode to a float messes it up.
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 bug report at http://bugs.php.net/?id=41246&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41246&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41246&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41246&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41246&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41246&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41246&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41246&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41246&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41246&r=support Expected behavior: http://bugs.php.net/fix.php?id=41246&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41246&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41246&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41246&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41246&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41246&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41246&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41246&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41246&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41246&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41246&r=mysqlcfg