Negin Nickparsa
2014-07-21 00:22:33 UTC
Hi
how PHP rounds the numbers in this case ?
$a = array(
0.5 => 1,
0.8 => 2,
1.2 => 3,
1.8 => 4,
);
print_r($a);
echo round(0.5);
we cannot have float keys so they will be rounded but I am wondering for
example rounding 0.5 will return 1 so from 0.1 to 0.4 all will be rounded
to 0
so it seems it is not doing the logic like the round function because the
$a output is :
Array ( [0] => 2 [1] => 4 )
what is the logic here?
Sincerely
Negin Nickparsa
how PHP rounds the numbers in this case ?
$a = array(
0.5 => 1,
0.8 => 2,
1.2 => 3,
1.8 => 4,
);
print_r($a);
echo round(0.5);
we cannot have float keys so they will be rounded but I am wondering for
example rounding 0.5 will return 1 so from 0.1 to 0.4 all will be rounded
to 0
so it seems it is not doing the logic like the round function because the
$a output is :
Array ( [0] => 2 [1] => 4 )
what is the logic here?
Sincerely
Negin Nickparsa