Json_decode限制

时间:2016-01-28 15:16:41

标签: php json

我使用json_decode(),但由于某种原因,它修剪了最后的数字,例如:

$test = '[{"Endereco_POI":"","UF":"SP","IBGE_N":"3509502","IBGE":"350950","Municipio":"CAMPINAS","Bairro":"","CEP":"1305883","Numero":"","X":-47.17788692505713,"Y":-22.918751685387484,"Prioridade":6,"Score":100.0,"Erro":347.59,"EnderecoEncontrado":"1305883, CAMPINAS SP"}]';

echo "<pre>";
print_r(json_decode($test, TRUE));
echo "</pre>";

输出

Array
(
    [0] => Array
        (
            [Endereco_POI] => 
            [UF] => SP
            [IBGE_N] => 3509502
            [IBGE] => 350950
            [Municipio] => CAMPINAS
            [Bairro] => 
            [CEP] => 1305883
            [Numero] => 
            [X] => -47.177886925057
            [Y] => -22.918751685387
            [Prioridade] => 6
            [Score] => 100
            [Erro] => 347.59
            [EnderecoEncontrado] => 1305883, CAMPINAS SP
        )

)

如此输出-47.17788692505713输出-47.177886925057。

是什么原因以及如何解决?

2 个答案:

答案 0 :(得分:2)

检查 php.ini 文件设置:

  

精度

默认设置为14.从手册Description of core php.ini directives

  

浮点数中显示的有效位数。

答案 1 :(得分:1)

您有比PHP支持更多的小数位:

php > $y = -22.918751685387484;
php > echo $y;
-22.918751685387

如果需要那些尾随数字,则浮点值必须编码为JSON中的字符串:

php > $y = "-22.918751685387484";
php > echo $y;
-22.918751685387484