Re: json_decode/encode should return full precision values by default
Hi Yasuo
On Mon, Jul 27, 2015 at 11:17 PM, Yasuo Ohgaki <[email protected]> wrote:
>
> Get JSON data from Google maps and store the data using PHP, then
> users lose last 2 digits of fraction part by default. The value is changed
> and wrong. This is definitely a bug.
>
>
I don't really get why you use Google maps as an example. Do you actually
know what's the difference between two distances that differs after
rounding with precision 14?
I just tried it on
http://www.ig.utexas.edu/outreach/googleearth/latlong.html
and set
Lat 1: 51.602097123457 ; Long 1: -0.120667
Lat 2: 51.602097123458 ; Long 2: -0.120667
The difference is 1.114e-10 km which is 0.0001114 millimetres. Are you
actually serious about that? :)
> We can write
>
> $old = ini_set('precision', 17);
> json_encode($var);
> ini_set('precision', $old);
>
You can set it once in your ini file if you need such precision.
>
> everywhere to workaround this problem.
>
> Question is "Is this the way it should be?".
>
>
I have already said that using precision ini wasn't the best idea. However
json_encode is not the same as serialize and we should not ever change its
output in a bug fixing release. Doing that could cause also other issues as
this is a BC break. Lets imagine that someone set low precision on purpose
just to limit precision and save some space when transferring data . If you
change it, then it's screwed up because it will use different ini. We don't
know what people do in their code and we should not break it. As I said
this is not a bug but we could consider changing that if the RFC proposing
such change passes.
Cheers
Jakub
Thread (24 messages)