@ 2016-09-30T09:51:04Z <?php
$numbs = [1,2,50.2,5.43,1.22,1.9,10.999,-20.5,-15.8,-2.75];
foreach($numbs as $num) {
$mod = $num < 0 ? -1 : 1;
$absNum = abs($num);
if($absNum >= ((int) $absNum) + 0.75) {
// Round Up
$roundedNum = ceil($absNum) * $mod;
} else {
//Round Down
$roundedNum = floor($absNum) * $mod;
}
echo $num . ' Rounded to ' . $roundedNum . "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 1 Rounded to 1
2 Rounded to 2
50.2 Rounded to 50
5.43 Rounded to 5
1.22 Rounded to 1
1.9 Rounded to 2
10.999 Rounded to 11
-20.5 Rounded to -20
-15.8 Rounded to -16
-2.75 Rounded to -3
preferences:dark mode live preview
265.46 ms | 404 KiB | 291 Q