Hello
I have a question based on the following code:
session_start();
$n = 50.9096
$_SESSION['number'] = $n;
$file = session_encode();
echo $file;
and the output is: number|d:50.9095999999999975216269376687705516815185546875;
Why is storing that amount of "invented" decimals??
But if i previously assign a format to the number:
session_start();
$n = number_format(50.9096, 4, ".", "");
$_SESSION['number'] = $n;
$file = session_encode();
echo $file;
the output is: number|d:50.9096;
I have the WampServer Version 2.0 on a Windows XP machine.
Thanks in advance.
session_encode problem
Moderator: General Moderators
Re: session_encode problem
It's well-known trouble this float numbers. If you interested read manual
This php-code output not number|d:50.9096;
it's return number|s:7:"50.9096";
Same output you may get if use constructions:
This php-code output not number|d:50.9096;
Code: Select all
<?
session_start();
$n = number_format(50.9096, 4, ".", "");
$_SESSION['number'] = $n;
$file = session_encode();
echo $file;
?>
Same output you may get if use constructions:
Code: Select all
$n = "50.9096";
// or
$n = (string)50.9096;
-
aualtopoll
- Forum Newbie
- Posts: 2
- Joined: Thu Sep 11, 2008 12:26 am
Re: session_encode problem
thanks!