function roundDown($number, $nearest){ return $number - fmod($number, $nearest); } var_dump(roundDown(7.778, 0.5)); var_dump(roundDown(7.501, 0.5)); var_dump(roundDown(7.49, 0.5)); var_dump(roundDown(7.1, 0.5));