I write a logic to round value based on fraction part value. When i execute this code, elseif block is not executed. Here is my code
<?php
function roundRating($rating)
{
if($rating>=5 && $rating<0){
$rating=0;
}
$a=(int)$rating/1;
$b= $rating-$a;
if(($b>=.1) && ($b<=.2)){
$b=0;
$rating=$a;
}
elseif(($b>=.3 && $b<=.4)|| ($b>=.6 && $b<=.7)){
$b=.5;
$rating=$a+$b;
}
elseif(($b>=.8) && ($b<=.9)){
$b=1;
$rating=$a+$b;
$a=$rating;
}
else{}
return $rating;
}
echo roundRating(3.3);
?>
for this value 3.3, the output should be 3.5. But currently it will return passed value 3.3 instead of 3.5. Kindly help me to find out the problem in the above code. Thanks in advance.