PHP - Serialize floating points

前端 未结 9 1472
自闭症患者
自闭症患者 2021-01-02 02:19

I am generating 10 random floats between 6 and 8 (all for good reason), and writing them to a mysql database in a serialized form. But one quirk seems to emerge at the stora

9条回答
  •  既然无缘
    2021-01-02 03:17

    Setting your serialize_precision value in php.ini to -1 will solve the floating point issue, or you can set it to a value that you prefer, as per the specifications here: http://php.net/manual/en/ini.core.php#ini.serialize-precision

    PHP versions <= 5.3.5 shipped with the default value of "100", while the default now at version 7.0.33 is "17", although the package bundled with your distro might have shipped with a "-1"

    As pointed out in other responses, you can override this setting in the application itself or even a custom php.ini that your VirtualHost container or .htaccess specifies.

    I hope that helps :)

提交回复
热议问题