How to round a number to a multiple of 8 in PHP

1 Answer

0 votes
function roundToMultipleOf($number, $multipleOf) {
    return $multipleOf * round($number / $multipleOf);
}

echo roundToMultipleOf(9, 8) . "\n";
echo roundToMultipleOf(19, 8) . "\n";
echo roundToMultipleOf(71, 8) . "\n";



/*
run:

8
16
72

*/

 



answered Jun 8, 2024 by avibootz

Related questions

2 answers 144 views
2 answers 150 views
2 answers 135 views
2 answers 182 views
2 answers 126 views
2 answers 133 views
2 answers 111 views
...