Req #26992 [Com]: Problem with (float) typecasting

From: Date: Thu, 03 Apr 2014 14:49:53 +0000
Subject: Req #26992 [Com]: Problem with (float) typecasting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185073@lists.php.net to get a copy of this message
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: 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 Previous Comments: ------------------------------------------------------------------------ [2014-04-03 14:35:31] 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) ------------------------------------------------------------------------ [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

« previous php.bugs (#185073) next »