3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }

preferences:
46.04 ms | 402 KiB | 5 Q