Edit report at http://bugs.php.net/bug.php?id=51599&edit=1
ID: 51599
Updated by: [email protected]
Reported by: sdevilcry at gmail dot com
Summary: Serialize problem with float data
-Status: Open
+Status: Bogus
Type: Bug
Package: Unknown/Other Function
Operating System: Linux / Unix
PHP Version: Irrelevant
New Comment:
The output of serialize() isn't meant to be human-readable, it's meant
to be accurate enough that PHP can unserialise the data later into the
exact same values. That level of accuracy is a feature, not a bug, and
as you've already noted, it's due to the way IEEE floats are
represented.
Not a bug: closing.
Previous Comments:
------------------------------------------------------------------------
[2010-04-19 11:41:03] sdevilcry at gmail dot com
Description:
------------
The problem appears when I want to serialize data like this the test
script submitted
Output of var_dump :
string(201)
"a:2:{s:5:"exVAT";a:2:{i:0;d:12.1199999999999992184029906638897955417633056640625;i:1;d:12;}s:6:"incVAT";a:2:{i:0;d:4566768.679999999701976776123046875;i:1;d:34343.33999999999650754034519195556640625;}}"
As you can see, the float data became very long...
I saw that isn't a bug, but coming from floating data type :
=> http://www.math.byu.edu/~schow/work/IEEEFloatingPoint.htm
Test script:
---------------
// Test float
function NumericPoint($Data)
{
return round(floatval(str_replace(',','.', $Data)), 2);
}
$tab = array("12.1222", "12", "4566768.67676767",
"34343.34343434343434");
$infos = array("exVAT" => array(0 => NumericPoint($tab[0]),
1 => NumericPoint($tab[1])),
"incVAT" => array(0 => NumericPoint($tab[2]),
1 => NumericPoint($tab[3])));
$SeriaData = serialize($infos);
var_dump($SeriaData);
// End
Expected result:
----------------
I expect to see the good format of my float data
Actually, to patch this, I don't convert my string to a float and I use
str_replace on my serialize data to delete the double quote and change
's' by 'd'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51599&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.