|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25425 serialize() doesn't work properly with floating point
Submitted: 2003-09-08 02:24 UTC Modified: 2003-09-08 06:05 UTC
From: crescent at corruptinteractive dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: crescent at corruptinteractive dot com
New email:
PHP Version: OS:


 [2003-09-08 02:24 UTC] crescent at corruptinteractive dot com
This bug only appeared after upgrading from php 4.3.1 to php 4.3.3

When serializing an array of floating point values with a specific decimal value of significance (ie: thousandths), once the array is serialized, bogus values are stored after the hundredth decimal position.

Here is a short, simple example:

Reproduce code:
$array[0] = 0;
$array[1] = 1.111;
$array[2] = 2.222;
$array[3] = 3.333;
$array[4] = 4.444;
$array[5] = 5.555;

$array =  serialize($array);
echo "Array = $array";

Expected result:
Array = a:6:{i:0;i:0;i:1;d:1.111;i:2;d:2.222;i:3;d:3.333;i:4;d:4.444;i:5;d:5.555;}

Actual result:
Array = a:6:{i:0;i:0;i:1;d:1.1109999999999999875655021241982467472553253173828125;i:2;d:2.221999999999999975131004248396493494510650634765625;i:3;d:3.3330000000000001847411112976260483264923095703125;i:4;d:4.44399999999999995026200849679298698902130126953125;i:5;d:5.55499999999999971578290569595992565155029296875;}

Notice the bogus values after the hundredth decimal place for each array element.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-08 02:45 UTC] crescent at corruptinteractive dot com
Temporary fix - cast the array elements of float type to a string before serialize().

Use settype($array, "string")
 [2003-09-08 06:05 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

We had to fix several other weired things with serializing and floats. As a result we now store more digits. But still the value is the same. That's the way floating point values work - we simply can't hide that from you anymore.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Jan 28 04:03:34 2022 UTC