Searching for a function ro round numbers to the nearest multiple of 5
22 -> 20
23 -> 25
40 -> 40
46 -> 45
48 -> 50
and so on.
Tried this which always returns the higher value:
5 * ceil($n / 5);
Rounding to the Nearest 5 degrees PHP's round() function takes a decimal number (a.k.a. floating point number) and rounds up or down. In its most simple and default form, it will round the decimal to the nearest whole number. For example, round(3.457) will give you the result 3 .
If you need to round a number to the nearest multiple of 5, you can use the MROUND function and supply 5 for number of digits. The value in B6 is 17 and the result is 15 since 15 is the nearest multiple of 5 to 17.
The round() function rounds a floating-point number. Tip: To round a number UP to the nearest integer, look at the ceil() function. Tip: To round a number DOWN to the nearest integer, look at the floor() function.
You can use CEILING to round prices, times, instrument readings or any other numeric value. CEILING rounds up using the multiple supplied. You can use the MROUND function to round to the nearest multiple and the FLOOR function to round down to a multiple.
Use round()
instead of ceil()
.
5 * round($n / 5);
ceil()
rounds a floating point number up to its next integer in sequence. round()
will round to the nearest integer using standard rounding rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With