Round to a nearest multiple of a constant?

Obviously, we can round/floor/ceiling to the nearest integer but how can I round to, say, the nearest multiple of 45? This seems like it should be very easy, so I feel like I’m missing something simple.


I have no idea if there is a node for that, but this here should do what you want:

I just converted this code to BP:

int roundUp(int numToRound, int multiple) 
    if (multiple == 0) 
        return numToRound; 

    int remainder = abs(numToRound) % multiple;
    if (remainder == 0)
        return numToRound;
    if (numToRound < 0)
        return -(abs(numToRound) - remainder);
    return numToRound + multiple - remainder;

Yep, it sure does. Thanks, eXi.

Forgive me if I’m wrong, but I believe it could be done with just three nodes (seen below).

I may be missing something however.

Much more elegant.

Div and round nodes

Even more elegant!