在PHP7.1和7.2beta中,使用json_encode()函数处理float/double值时出现溢出问题。网上普遍认为是php.ini中serialize_precision项配置不当造成的,但实际修改该配置项并不能解决问题。对此,我参考网上的方法写了一个包,欢迎使用^_^。示例>>>$a=0.1+0.7=>0.8>>>printf('%.20f',$a)=>0.79999999999999993339>>>json_encode($a)=>"0.7999999999999999">>>\YaJson::encode($a)=>"0.8"用法修复精度并执行json_encode:$data=['a'=>0.1+0.7,'b'=>['string1','string2'],];\YaJson::encode($数据);只获取没有json_encode的修复数据:$data=['a'=>0.1+0.7,'b'=>['string1','string2'],];\YaJson::准备($数据);安装安装包文件composerrequire"seekerliu/laravel-another-json:dev-master"配置Laravel5.5Laravel5.5安装新包后默认会执行@phpartisanpackage:discover命令,所以不能进行以下操作.注册ServiceProvider和Facade:phpartisanpackage:discover如果需要修改默认的循环深度和精度位数,创建配置文件:phpartisanvendor:publishLaravel5.4及以下注册ServiceProvider和Facade:'providers'=>[//...Seekerliu\YaJson\ServiceProvider::class,],'aliases'=>[//...'YaJson'=>Seekerliu\YaJson\Facade::class,]如果需要修改默认循环深度和精度数字,然后创建配置文件:phpartisanvendor:publish--provider="Seekerliu\YaJson\ServiceProvider"Github:https://github.com/seekerliu/laravel-another-json感谢博主提供思路:http://www.itread01.com/articles/1489774743.html
