Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103639 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77664 invoked from network); 26 Dec 2018 19:22:23 -0000 Received: from unknown (HELO mail-io1-f44.google.com) (209.85.166.44) by pb1.pair.com with SMTP; 26 Dec 2018 19:22:23 -0000 Received: by mail-io1-f44.google.com with SMTP id t24so12569080ioi.0 for ; Wed, 26 Dec 2018 07:53:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Bf9j2m5DldP9udv3yPEzu25VoDoYdZg/khJBALJ5myY=; b=QIiL0pf0VrXD9IRatqJqxmzrj2/3uZGOiiNRcqMzbmkCvRKthpP7DuYXdPHUhABnf8 Xjl1ue/A460cYwVk50VyUvnjWUEyptZ0K0tsrvg9chXd0p24ELsxABTBZsWS0CeHsgRu lzxww+2MB+c563C2sHGXf/JoJF9T6OVF04Qi4Ll2OjtEWgzNBJbUiLyo5ubjXu+RYXAR R3oYiuTXZTazarjuWDFKZo5YSgnJuswAiBdGsChGNy6OCNPjhLq/1AQqM6PwGPGMp3oI XhjelWlFGoVH5Zj5hdFFsD50sxED7ndx0JbeDNLrzPbpIVdcoIA1JE9QFSQWazn3s4vV 2uHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Bf9j2m5DldP9udv3yPEzu25VoDoYdZg/khJBALJ5myY=; b=aUisjnpnf+32WIyzNb8O2zXozMtxwoyL/jf/XEf/2iJWYUW+0yIZRQeTX4Yh1XgAHy TDRsu+JSszyGtEZ9Mo8wrNxVJMNx0ltkcNHFWF2nUC2Jz4ZUZQTO63cXExxijYkRAmfj MkT2flLKjxvyCcA/BwisDXuxONHgPs0vxPVAtyPtWdFPqJxZmOvOp1z7TdOvJbptca/s NgP8eKtLM1AnFNXO8W3XFkeIiLNzXz3Qr3DyQG39b1+/s8uow3dh5+gi0VAdC0QM71Kx VAzf2xQZxSzjlmQV5G7rDSvLR4e5hVe5ucNNnWeNH2ryFxiC8oflsUOotj5MXBjjkXC5 5lUA== X-Gm-Message-State: AJcUukcjz08V24jS1bPj40A41kzS8dmES0LHYrXgMWJYa9mMJF+9l6xy q4NrqJu+BVB3BBRL+BOuceJU35a2LP223LlMCoQ= X-Google-Smtp-Source: ALg8bN5mcepKCssoxE7lv321DtiOSwLDPcN9Ll79M5I0GBoOEO70pm8YgwNRKoJuvXPhoUqPFiEPpDUm9y+GXW54bps= X-Received: by 2002:a6b:5804:: with SMTP id m4mr13279447iob.47.1545839597629; Wed, 26 Dec 2018 07:53:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Dec 2018 16:52:59 +0100 Message-ID: To: "Christoph M. Becker" Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000018b40b057deed4c0" Subject: Re: [PHP-DEV] Inconsistent float to string vs. string to float casting From: nikita.ppv@gmail.com (Nikita Popov) --00000000000018b40b057deed4c0 Content-Type: text/plain; charset="UTF-8" On Wed, Dec 26, 2018 at 4:48 PM Christoph M. Becker wrote: > Hi! > > 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) > > As for me, the question is not *if*, but rather *when* and *how* this > inconsistency should be resolved. Regarding the *when*, it seems to me > we have to wait for the next major version, i.e. PHP 8. Regarding the > *how* I tend to prefer the non-locale aware behavior, i.e. float to > string conversion should always produce a decimal *point*. Users still > can explicitly use number_format() or NumberFormatter if they wish. > > Thoughts? > Yes, please. Locale-sensitive library functions are bad enough, but core language behavior should *never* be locale-sensitive. I'm definitely in favor of making float to string casts locale-independent in PHP 8. Nikita --00000000000018b40b057deed4c0--