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, '.', ''); } define("ENDL", "\n"); print roundDownToHalf(4.9) . ENDL; print roundDownToHalf(4.8) . ENDL; print roundDownToHalf(4.5) . ENDL; print roundDownToHalf(3.8) . ENDL; print roundDownToHalf(2.3) . ENDL; print roundDownToHalf(1.0) . ENDL; ?>
Output for 4.3.0 - 7.1.0
4.5 4.5 4.5 3.5 2.0 1.0