#48315 [NEW]: Type conversion into a float respects the numeric settings of the locale
| From: | alef0 at freenet dot de | Date: | Mon, 18 May 2009 15:26:02 +0000 |
| Subject: | #48315 [NEW]: Type conversion into a float respects the numeric settings of the locale | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-137444@lists.php.net to get a copy of this message | ||
From: alef0 at freenet dot de
Operating system: gentoo
PHP version: 5.2CVS-2009-05-18 (CVS)
PHP Bug Type: Math related
Bug description: Type conversion into a float respects the numeric settings of the locale
Description:
------------
PHP version: 5.2.6RC4-pl0-gentoo
Conversion using floatval() or (float) respects the numeric settings of
the locale.
THIS IS VERY DANGEROUS CAUSE YOU WILL GET WRONG RESULTS BY APPLYING ANY
MATH METHODE ON CONVERTED FLOATS!
Reproduce code:
---------------
$var = '122.34343The'; //expected float: 122.34343
setlocale(LC_NUMERIC, 'en_US.utf8');
$float_value_of_var = (float) $var;
print 'Locale dec sep point: (float) ' . $var . ' = ' .
$float_value_of_var;
$float_value_of_var = floatval($var);
print ' or floatval(' . $var . ') = ' . $float_value_of_var . "<br
/><br
/>\n\n";
setlocale(LC_NUMERIC, 'de_DE.utf8');
$float_value_of_var = (float) $var;
print 'Locale dec sep comma: (float) ' . $var . ' = ' .
$float_value_of_var;
$float_value_of_var = floatval($var);
print ' or floatval(' . $var . ') = ' . $float_value_of_var . "<br
/><br
/>\n\n";
Expected result:
----------------
Locale dec sep point: (float) 122.34343The = 122.34343 or
floatval(122.34343The) = 122.34343
Locale dec sep comma: (float) 122.34343The = 122.34343 or
floatval(122.34343The) = 122.34343
Actual result:
--------------
Locale dec sep point: (float) 122.34343The = 122.34343 or
floatval(122.34343The) = 122.34343
Locale dec sep comma: (float) 122.34343The = 122,34343 or
floatval(122.34343The) = 122,34343
--
Edit bug report at http://bugs.php.net/?id=48315&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48315&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48315&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48315&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48315&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48315&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48315&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48315&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48315&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48315&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48315&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48315&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48315&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48315&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48315&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48315&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48315&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48315&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48315&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48315&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48315&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48315&r=mysqlcfg