From: Operating system: PHP version: 5.2.17 Package: Math related Bug Type: Bug Bug description:Casting float->string->float with locale
Description: ------------ When LC_ALL or LC_NUMERIC is used with setlocale casting a float as a string converts the number to the formatted locale (1234.56 to 1.234,56 instead of 1,234.56 for Italian). But when casting from a string to a float locale is not used and decimal precision is lost. I understand this has been a problem for a long time (since PHP 4 up to 5.3 at least). The obvious "work around" for me is avoid LC_NUMERIC and LC_ALL completely. Personally I would rather casting to a string NOT convert using the locale (so have it stay "1234.56"). A data type should not be locale aware. It's like assuming that a decimal number is monetary. If a float needed to be displayed with locale number_format should be used (where the default separators fit the locale). If casting to a string must be locale aware, shouldn't casting a string to a float be locale aware as well? On top of that, could it understand the thousands separator and simply ignore it? Test script: --------------- setlocale(LC_NUMERIC, 'en_US'); print (float)(string)1234.56; print '<br />'; setlocale(LC_NUMERIC, 'it_IT'); print (string)(float)(string)1234.56; print '<br />'; print (string)(float)'1.234,56'; Expected result: ---------------- 1234.56 1234,56 1234,56 Actual result: -------------- 1234.56 1234 1,234 -- Edit bug report at http://bugs.php.net/bug.php?id=53711&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53711&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53711&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53711&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53711&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53711&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53711&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53711&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53711&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53711&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53711&r=support Expected behavior: http://bugs.php.net/fix.php?id=53711&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53711&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53711&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53711&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53711&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53711&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53711&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53711&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53711&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53711&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53711&r=mysqlcfg
