i need a function that can round from a defined custom range...
for example:
0.01 - 0.39 = round to 0
0.40 - 0.74 = round to 0.5
0.75 - 0.99 = round to 1
if number is 2.33 it should show as 2.0
if number is 2.67 it should show as 2.5
if number is 2.89 it should show as 3.0
i tried something but doesn't work at all...
code:
$range1 = range(0.01, 0.39, 0.01);
$range2 = range(0.40, 0.74, 0.01);
$range3 = range(0.75, 0.99, 0.01);
function round_range($num) {
global $range1, $range2, $range3;
if (in_array($num, $range1))
return round($num, 0, PHP_ROUND_HALF_DOWN);
else if (in_array($num, $range2))
return round($num, 0, PHP_ROUND_HALF_DOWN);
else if (in_array($num, $range3))
return round($num, 0, PHP_ROUND_HALF_DOWN);
else
return "error";
}
echo round_range(0.35);