#48315 [Opn]: Type conversion into a float respects the numeric settings of the locale
| From: | alef0 at freenet dot de | Date: | Mon, 18 May 2009 15:41:32 +0000 |
| Subject: | #48315 [Opn]: Type conversion into a float respects the numeric settings of the locale | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137446@lists.php.net to get a copy of this message | ||
ID: 48315
User updated by: alef0 at freenet dot de
Reported By: alef0 at freenet dot de
Status: Open
Bug Type: Math related
Operating System: gentoo
PHP Version: 5.2CVS-2009-05-18 (CVS)
New Comment:
At [27 Feb 2007 12:27pm UTC] tony2001@php.net wrote:
( ... ) we DON'T want scripts to depend on locale or we may end up
with
scripts working/not working with particular locales. (See Bug #40653)
Previous Comments:
------------------------------------------------------------------------
[2009-05-18 15:26:02] alef0 at freenet dot de
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 this bug report at http://bugs.php.net/?id=48315&edit=1