Req #26992 [Com]: Problem with (float) typecasting
Edit report at https://bugs.php.net/bug.php?id=26992&edit=1
ID: 26992
Comment by: tomasz dot kane at gmail dot com
Reported by: hkh at netnords dot dk
Summary: Problem with (float) typecasting
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: linux
PHP Version: 4.3.4
Block user comment: N
Private report: N
New Comment:
More example:
---- code:
var_dump(filter_var(1.1, FILTER_VALIDATE_FLOAT));
setlocale(LC_NUMERIC, "pl_PL.utf8");
var_dump(filter_var(1.1, FILTER_VALIDATE_FLOAT));
---- result:
double(1.1)
bool(false)
---- expected:
double(1.1)
double(1.1)
Previous Comments:
------------------------------------------------------------------------
[2004-01-21 09:35:38] hkh at netnords dot dk
I just took a look at
http://dk2.php.net/manual/en/language.types.float.php#language.types.float.casting
As far as I can see, commas are not a legal character in a float.
------------------------------------------------------------------------
[2004-01-21 09:23:26] hkh at netnords dot dk
Description:
------------
When using (float)$dd for typecasting a string to a float, I get a wrong result back, because PHP
convert . to ,
Later using the result outside PHP troubles begin.
Thinks it happens because we have used setLocale('da_DK'), because we i Denmark use ,
instead of .
Why just use . everytime, as in other programming-languages ?
Reproduce code:
---------------
print ((float)'1.5').'<br>'; // Result 1,5
print ((float)'1,5').'<br>'; // Result 1 - Fine with me
Expected result:
----------------
1.5
1
Actual result:
--------------
1,5
1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=26992&edit=1
Thread (5 messages)