I\'m looking for a method that can round a number up to the nearest multiple of another. This is similar Quantization.
Eg. If I want to round 81 up to the
If you're using a lot of these on a relatively slow platform, you may eliminate the multiplication by using a variant of:
t = m + n - 1; return (t - (t % n));
Of course, if you can limit your multiple to values of 2^n, then the modulus operation may also be deprecated in favour of its logical equivalent (usually "&").
Incidentally, the "RoundUp" function illustrated above is seriously flawed and will only round down correctly when {(m % n) == (n - 1)}; rounding down is implicit for integer division and as such, does not require compensation.