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

在PHP 7.3.8版本中,使用`json_encode`处理浮点类型数据时遇到精度丢失的问题。为了解决这个问题,可以调整`php.ini`配置文件中的`serialize_precision`参数,将其设置为16或更高的值,确保在序列化和反序列化过程中浮点数的精度得以保持。此设置同样适用于`json_encode`时的双精度数值编码。
摘要由CSDN通过智能技术生成

新项目用的 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值