简体   繁体   English

Json_decode限制

[英]Json_decode limit

I'm using json_decode() but for some reason it trims the last digits, example: 我正在使用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>";

the output is 输出是

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
        )

)

so insted of -47.17788692505713 it outputs -47.177886925057. 如此输出-47.17788692505713它输出-47.177886925057。

Whats the reason for that and how do I fix it? 是什么原因,我该如何解决?

Checking the php.ini file setting for: 检查php.ini文件设置:

precision 精确

By default it is set to 14. From the manual Description of core php.ini directives : 默认情况下,它设置为14.从手册说明核心php.ini指令

The number of significant digits displayed in floating point numbers. 浮点数中显示的有效位数。

You have more decimal places than PHP supports: 您有比PHP支持更多的小数位:

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

If you need those trailing digits, then the float values have to encoded as strings inside the JSON: 如果你需要那些尾随数字,那么float值必须在JSON中编码为字符串:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM