Re: Proposal: change precision for output functions

From: Date: Mon, 07 Jan 2019 18:17:45 +0000
Subject: Re: Proposal: change precision for output functions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-103696@lists.php.net to get a copy of this message
> 07.01.2019, 20:24, "Thomas Bley" <mails@thomasbley.de>: > > 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/

« previous php.internals (#103696) next »