Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103696 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86199 invoked from network); 7 Jan 2019 21:43:51 -0000 Received: from unknown (HELO forward500j.mail.yandex.net) (5.45.198.250) by pb1.pair.com with SMTP; 7 Jan 2019 21:43:51 -0000 Received: from mxback15o.mail.yandex.net (mxback15o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::66]) by forward500j.mail.yandex.net (Yandex) with ESMTP id 0C9CA11C0ED2; Mon, 7 Jan 2019 21:17:47 +0300 (MSK) Received: from localhost (localhost [::1]) by mxback15o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id taBixqp0Wu-Hjg8hnan; Mon, 07 Jan 2019 21:17:46 +0300 Received: by myt6-add70abb4f02.qloud-c.yandex.net with HTTP; Mon, 07 Jan 2019 21:17:45 +0300 Envelope-From: semen@sam002.net To: Thomas Bley , "internals@lists.php.net" In-Reply-To: <20190107172439.47D006480230@dd16914.kasserver.com> References: <20190107172439.47D006480230@dd16914.kasserver.com> MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 07 Jan 2019 21:17:45 +0300 Message-ID: <44741741546885065@myt6-add70abb4f02.qloud-c.yandex.net> Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 Subject: Re: [PHP-DEV] Proposal: change precision for output functions From: php@sam002.net (Semen Dubina) > 07.01.2019, 20:24, "Thomas Bley" : > > Hello, > > good point, having: > > echo ini_get('precision') . PHP_EOL; > echo ini_get('serialize_precision') . PHP_EOL; > echo json_encode(array('price' => round('45.99', 2))) . PHP_EOL; > echo (0.1+0.7), json_encode(0.1+0.7) . PHP_EOL; > > gives (https://3v4l.org/ldgo8): > > Output for 7.1.0 - 7.3.0 >     14 >     -1 >     {"price":45.99} >     0.80.7999999999999999 > > Output for 5.3.6 - 5.6.38, 7.0.0 - 7.0.33 >     14 >     17 >     {"price":45.99} >     0.80.8 > > what is the preferred way to upgrade from php 5.6 to 7.x in order to get the same results? > > Regards > Thomas > Force 'serialize_precision': https://3v4l.org/coaWm But remember - a float is not suitable for output. You need rounded and formatted manually. P.S. Try with JS: `JSON.stringify(0.1+0.7);` -- Semen V. Dubina https://sam002.net/