Re: Inconsistent float to string vs. string to float casting

From: Date: Fri, 04 Jan 2019 16:56:19 +0000
Subject: Re: Inconsistent float to string vs. string to float casting
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-103682@lists.php.net to get a copy of this message
On 26.12.2018 at 16:47, Christoph M. Becker wrote: > Regarding the decimal separator (aka. decimal point), the behavior of > casting float to string is inconsistent with casting string to float. > While the former regards the current locale, the latter always expects a > decimal point regardless of the locale. This breaks round-trips for > locales which use something else than a dot as decimal separator (e.g. > German, which uses a comma), for instance: > > $float = 1/3; // float(0,33333333333333) > $string = (string) $float; // string(16) "0,33333333333333" > $float = (float) $string; // float(0) Well, there's a special case, though: $string = (1/3) . 'foo'; // string(19) "0.33333333333333foo" This is caused by a compile-time optimization, which obviously occurs before any locale *can* be set. -- Christoph M. Becker

« previous php.internals (#103682) next »