3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function roundDownToHalf($number) { $remainder = ($number * 10) % 10; $half = $remainder >= 5 ? 0.5 : 0; $value = floatval(intval($number) + $half); return number_format($value, 1, '.', ''); } print roundDownToHalf(4.9) . "\n"; print roundDownToHalf(4.8) . "\n"; print roundDownToHalf(4.5) . "\n"; print roundDownToHalf(3.8) . "\n"; print roundDownToHalf(2.3) . "\n"; print roundDownToHalf(1.0) . "\n"; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
4.5 4.5 4.5 3.5 2.0 1.0