php 7.3 使用 json_encode 函数造成浮点类型数据出现精度问题

新项目用的 php 7.3.8 版本,在使用过程中发现 浮点类型 数据经过 json_encode 之后会出现精度问题。

调整 php.ini 中 serialize_precision (序列化精度) 的大小来解决这个问题。

; When floats & doubles are serialized store serialize_precision significant
; digits after the floating point. The default value ensures that when floats
; are decoded with unserialize, the data will remain the same.
; The value is also used for json_encode when encoding double values.
; If -1 is used, then dtoa mode 0 is used which automatically select the best
; precision.
serialize_precision = 16


版权声明:本文为qq_39399594原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。