A way to do this without a lot of variables and casting?
So you're looking for

int result = (int)Math.round((float)n/(float)d) * d;


(assuming you are only interested in the intermediate values for this particular calculation)

Here's a test case with an alternative:

import junit.framework.TestCase;

public class TestModulo extends TestCase {

    private final static int d = 7;

    public void testModulo() throws Exception {
        for (int n = 0; n &lt; 30; n++) {
            assertEquals("fails for " + n, f2(n), f1(n));
        }
    }

    private int f1(int n) {
        return (int) Math.round((float) n / (float) d) * d;
    }

    private int f2(int n) {
        return ((n + d / 2) / d) * d;
    }

}


You can solve your problem using only integer math.