php.net |  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
Votes:4
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hkh at netnords dot dk
New email:
PHP Version: OS:

 

 [2004-01-21 09:23 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-21 09:35 UTC] 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.
 [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:

double(1.1)
bool(false)

---- expected:

double(1.1)
double(1.1)
 [2014-04-03 14:49 UTC] tomasz dot kane at gmail dot com
BTW:

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] krakjoe@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2015-02-18 07:36 UTC] krakjoe@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC