|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #26992 Problem with (float) typecasting
Submitted: 2004-01-21 09:23 UTC Modified: 2015-02-18 07:36 UTC
Avg. Score:3.8 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: hkh at netnords dot dk Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 4.3.4 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: hkh at netnords dot dk
New email:
PHP Version: OS:


 [2004-01-21 09:23 UTC] hkh at netnords dot dk
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-21 09:35 UTC] hkh at netnords dot dk
I just took a look at

As far as I can see, commas are not a legal character in a float.
 [2014-04-03 14:35 UTC] tomasz dot kane at gmail dot com
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:


---- expected:

 [2014-04-03 14:49 UTC] tomasz dot kane at gmail dot com

Ubuntu 13.10

$ php -v
PHP 5.5.3-1ubuntu2.2 (cli) (built: Feb 28 2014 20:06:05) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
 [2015-02-18 07:36 UTC]
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2015-02-18 07:36 UTC]
Whether the behaviour is correct is debatable.

What is not debatable is that it is expected by current code, so that making this change would require a rather substantial break in BC, of the kind that requires an RFC.

I'm therefore going to mark this request as won't fix.

Sorry about the wait.
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 16:01:28 2019 UTC