What is the easiest way to round up x so that it is divisible by m ?
For example,
if x = 114, m =4, then the round up should be 116
or
if x = 119, m=5, then the round up should be 120
What is the easiest way to round up x so that it is divisible by m ?
For example,
if x = 114, m =4, then the round up should be 116
or
if x = 119, m=5, then the round up should be 120
Divide the number by the require multiple, round the result to the next integer and multiply again by the required multiple.
E.g.: 116 / 5 = 23.1, round to 24, 24 ยท 5 = 120
Use modulo (%%):
roundUP <- function(x, m){x + m - x %% m}
roundUP(114, 4)
[1] 116
roundUP(119, 5)
[1] 120
roundUP(118, 5)
[1] 120
roundUP(113, 5)
[1] 115