Hi all,

Created bug report for this issue.
https://bugs.php.net/bug.php?id=70137


--
Yasuo Ohgaki
yohg...@ohgaki.net

On Sun, Jul 26, 2015 at 7:01 AM, Yasuo Ohgaki <yohg...@ohgaki.net> wrote:

> Hi all,
>
> I had to work with Google Map API and need to handle values precisely.
> Fortunately, it seems values are IEEE double, but I get rounded float
> values by default.
>
> For example,
> <?php
> $json = '
> {
>    "results" : [
>       {
>          "elevation" : 1608.637939453125,
>          "location" : {
>             "lat" : 39.73915360,
>             "lng" : -104.98470340
>          },
>          "resolution" : 4.771975994110107
>       },
>       {
>          "elevation" : -50.78903579711914,
>          "location" : {
>             "lat" : 36.4555560,
>             "lng" : -116.8666670
>          },
>          "resolution" : 19.08790397644043
>       }
>    ],
>    "status" : "OK"
> }
> ';
>
> var_dump(json_decode($json));
> ?>
>
> object(stdClass)#5 (2) {
>   ["results"]=>
>   array(2) {
>     [0]=>
>     object(stdClass)#1 (3) {
>       ["elevation"]=>
>       float(1608.6379394531)
>       ["location"]=>
>       object(stdClass)#2 (2) {
>         ["lat"]=>
>         float(39.7391536)
>         ["lng"]=>
>         float(-104.9847034)
>       }
>       ["resolution"]=>
>       float(4.7719759941101)
>     }
>     [1]=>
>     object(stdClass)#3 (3) {
>       ["elevation"]=>
>       float(-50.789035797119)
>       ["location"]=>
>       object(stdClass)#4 (2) {
>         ["lat"]=>
>         float(36.455556)
>         ["lng"]=>
>         float(-116.866667)
>       }
>       ["resolution"]=>
>       float(19.08790397644)
>     }
>   }
>   ["status"]=>
>   string(2) "OK"
> }
>
>
> json_decode()/json_encode() must be able to handle precise IEEE double
> value by _default_.
>
> serialize() is changed to use max precision. json_decode/encode should do
> the same at least.
>
> I think this change should be provided as bug fix.
> Any comments?
>
> --
> Yasuo Ohgaki
> yohg...@ohgaki.net
>

Reply via email to