#45221 [Opn->Bgs]: Number in string conversion with comma separator
| From: | felipe@php.net | Date: | Tue, 10 Jun 2008 13:11:36 +0000 |
| Subject: | #45221 [Opn->Bgs]: Number in string conversion with comma separator | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-125645@lists.php.net to get a copy of this message | ||
ID: 45221
Updated by: felipe@php.net
Reported By: walterquez at yahoo dot com
-Status: Open
+Status: Bogus
Bug Type: Strings related
Operating System: Windows 2003
PHP Version: 5.2.6
New Comment:
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
That is expected, the float value doesn't uses comma.
http://docs.php.net/float
Previous Comments:
------------------------------------------------------------------------
[2008-06-09 18:15:34] walterquez at yahoo dot com
Description:
------------
When numbers in a string containing comma separators are converted to
any numeric type, it strips any number to the right of the commas.
Reproduce code:
---------------
<?php
$a = '200';
$b = '1,000';
if ($a > $b) echo 'A is bigger'; else echo 'B is bigger';
?>
For some reason, because $b has a comma, it converts $b to 1, not 1000.
If you remove the comma, it works fine.
To prove it, check the following.
$b = (int) $b; // same with (float), (double) or (real)
echo $b; // it prints 1, not 1000.
I even included, setlocale(LC_ALL, 'en'); but no luck.
Expected result:
----------------
B is bigger
Actual result:
--------------
A is bigger
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45221&edit=1