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 132 views
2 answers 138 views
2 answers 126 views
2 answers 168 views
2 answers 121 views
2 answers 125 views
2 answers 107 views
...