-
I want to round up the value with 0 or 5 based on the below conditions. For example:
160.1 to 162.5 ---> 160 (value expected) 162.6 to 167.5 ---> 165 (value expected) 167.6 to 169.9 ---> 170 (value expected)
Below is my code which i tried with a scenario:
$main_value=3831.25;
if(is_int($main_value))
{
$main_value=number_format($main_value,1);
}
$arr = explode(".", $main_value);
$firstvalue=substr($arr['0'],-1);
$secoundvalue=substr($arr['1'],0,1);
//echo "<pr>";print_r($firstvalue.$secoundvalue);exit;
$default=$firstvalue.$secoundvalue;
//echo "<pr>";print_r($default);exit;
if($default>=1 && $default<=25){
echo $output=$main_value-($default/10);
}elseif ($default>25 && $default<=50) {
$temp_val=50-$default;
echo $output=$main_value+($temp_val/10);
}elseif($default>50 && $default<=75){
$temp_val=$default-50;
echo $output=$main_value-($temp_val/10);
}else{
$temp_val=100-$default;
echo $output=$main_value+($temp_val/10);
}
- But the output i coming as 3830.05. Is there any other way to get the expected output.