From:             
Operating system: Linux / Unix
PHP version:      Irrelevant
Package:          Unknown/Other Function
Bug Type:         Bug
Bug description:Serialize problem with float data

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 bug report at http://bugs.php.net/bug.php?id=51599&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51599&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51599&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51599&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51599&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51599&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51599&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51599&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51599&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51599&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51599&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51599&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51599&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51599&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51599&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51599&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51599&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51599&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51599&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51599&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51599&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51599&r=mysqlcfg

Reply via email to