Bug #77278 [Com]: floatval(strval(value)) truncates if locale's decimal_point isn't a period
| From: | spam2 at rhsoft dot net | Date: | Mon, 10 Dec 2018 21:45:14 +0000 |
| Subject: | Bug #77278 [Com]: floatval(strval(value)) truncates if locale's decimal_point isn't a period | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218382@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77278&edit=1
ID: 77278
Comment by: spam2 at rhsoft dot net
Reported by: spam2 at rhsoft dot net
Summary: floatval(strval(value)) truncates if locale's
decimal_point isn't a period
Status: Verified
Type: Bug
Package: Scripting Engine problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
nonsense! show me the PHP code where type casts after setlocale() change tehir meaning!
you can't even distinct what happens by use setlocale('whatever', NULL) before and
after the tidy call because i get always get de_DE.UTF-8 as result
Previous Comments:
------------------------------------------------------------------------
[2018-12-10 21:41:36] requinix@php.net
You can't blame PHP for Tidy's problem. If they change locale (already a dangerous
operation since it's not thread-safe) and then don't revert it to the previous setting
when they're done, that's their fault.
------------------------------------------------------------------------
[2018-12-10 21:33:13] spam2 at rhsoft dot net
working as intended?
a random linked library calls locale and the whole behavior of internal php typecast changes for
every follow-up code in a PHP application is intended? really?
------------------------------------------------------------------------
[2018-12-10 21:29:50] nikic@php.net
I think we should get rid of the locale-dependent float to string cast in PHP 8, but for now this is
working as "intended". We should definitely *not* make string to float cast
locale-sensitive as well, that would only make a bad situation worse.
------------------------------------------------------------------------
[2018-12-10 19:37:59] requinix@php.net
var_dump(setlocale(LC_NUMERIC, "de_DE", "German_Germany"));
var_dump(1 / 2); float 0,5
var_dump(strval(1 / 2)); // string "0,5"
var_dump(floatval(strval(1 / 2))); // float 0
------------------------------------------------------------------------
[2018-12-10 18:47:07] spam2 at rhsoft dot net
> but that there's an inconsistency between casting floats
> to strings and strings to floats when it comes to the decimal symbol?
that's exactly the point - oustide of format functions my locale de_DE.UTF-8 normally
don't matter and shouldn't do so but afer a simple tidy call anywhere every following php
code doing type casts on float values becomes a lottery
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=77278
--
Edit this bug report at https://bugs.php.net/bug.php?id=77278&edit=1