dongming4994 2013-03-13 09:33
浏览 62
已采纳

unserialize + php给出转换原始值

Here is my string I want unserialize this string.

$string3 = 'a:3:{i:0;a:2:{s:5:"value";d:4.0999999999999996;s:7:"players";a:2:{i:6;i:6;i:7;i:7;}}i:1;a:2:{s:5:"value";d:10.899999999999999;s:7:"players";a:1:{i:7;i:7;}}i:2;a:2:{s:5:"value";d:1.7763568394002505E-15;s:7:"players";N;}}';

and it gives below result

Array
(
[0] => Array
    (
        [value] => 4.1 // this value converted to 4.1 original was see in the string it was 4.0999999999999996
        [players] => Array
            (
                [6] => 6
                [7] => 7
            )

    )

[1] => Array
    (
        [value] => 10.9 // this value converted to 10.9 original was see in the string it was 10.899999999999999
        [players] => Array
            (
                [7] => 7
            )

    )

[2] => Array
    (
        [value] => 1.7763568394003E-15
        [players] => 
    )

)

it converts array value to 4.1 and 10.9 etc. I want original value not converted.

  • 写回答

1条回答 默认 最新

  • doushangxianq07480 2013-03-13 11:25
    关注

    It is hard for computers to handle floats with precision. Without going into much details PHP simply has set a value for the max amount of floating point values. This is set in the precision config property. It is probably set to 14, so every float that has 14 or more floating numbers will be rounded.

    So what you need to do is increase the precision value in your php.ini. Or change it with ini_set('precision', 20).

    That should do the trick.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题