Welcome Guest, Not a member yet? Register   Sign In
Flashdata is messing up numbers
#1

[eluser][email protected][/eluser]
Hello,

I am storing a decimal number in the flash_data (ie. $42.99) and the serialize function inside the set_flash_data() is appending too many decimals. Later, when I retrieve the value there are issues with comparing the values. Has anyone come across this problem?

Code:
<?php
$val = 42.99;
var_dump($val);  // initial value: float(0.333333333333)
echo '<br/><br/>';
$val = serialize($val);
var_dump($val);  // standart float format: string(55) "d:0.333333333333333303727386009995825588703155517578125;"
echo '<br/><br/>';
$val = preg_replace('/d:([0-9]+(\.[0-9]+)?([Ee][+-]?[0-9]+)?);/e', "'d:'.((float)$1).';'", $val);
var_dump($val);  // compact float format: string(10) "d:0.333333333333;"
echo '<br/><br/>';
$val = unserialize($val);
var_dump($val);  // unserialization successed: float(0.333333333333)
echo '<br/><br/>';
$val = serialize($val);
var_dump($val);  // but value is rounded off!: string(55) "d:0.3333333333330000147753935380023904144763946533203125;"
echo '<br/><br/>';
?&gt;


Messages In This Thread
Flashdata is messing up numbers - by El Forum - 10-06-2008, 11:45 AM
Flashdata is messing up numbers - by El Forum - 10-07-2008, 03:27 AM
Flashdata is messing up numbers - by El Forum - 10-08-2008, 11:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB