I ve got a strange php behaviour with floating value
$array_test["test"]= round($value,2); //first I round up a value
echo $array_test["test"]; //0,66
$s_array_test= serialize($array_test); //serializing the array
var_dump($s_array_test) // (...)s:4:"test";d:0.66000000000000003108624468950438313186168670654296875;}(...)
This is pretty annoying cause the serialized array is stored into a db a use more space…
How to fix this ?
thx
First of all read the section about floats in the manual http://php.net/manual/en/language.types.float.php
You may use
sprintf()(instead ofround()) to convert the float into a fixed-sized stringBut I suggest you to create and use a real database schema. You don’t need a database at all, if you just put unstructured strings in it. You can use simple flatfiles instead.