Re: Change default serialize precision from 100 to 17
| From: | Nicolas Grekas | Date: | Tue, 08 Feb 2011 20:05:05 +0000 |
| Subject: | Re: Change default serialize precision from 100 to 17 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51436@lists.php.net to get a copy of this message | ||
> ini_set('precision', 17);
After some testings, here is what I get :
<?php
ini_set('precision', 14);
echo 0.1; // 0.1
echo 0.2; // 0.2
echo 0.3; // 0.3
ini_set('precision', 17);
echo 0.2; // 0.10000000000000001
echo 0.2; // 0.20000000000000001
echo 0.3; // 0.29999999999999999
?>
The default precision of 14 (or 12) must have been chosen to address
this overlong string representation of many simple floats ?
While I agree with you that any data loss must be forbidden, couldn't
this also break existing code ?
Would it be possible to "displays a value based on the shortest
decimal fraction that rounds correctly back to the true binary value",
like python 2.7 and 3.1 do ?
(http://docs.python.org/tutorial/floatingpoint.html)
Just my 2cts :)
Nicolas