I'm trying to write a small function which has to, at one point, round a number UP to the nearest multiple of 5.
In theory, the results should be:
4 rounds up to 5
5 rounds up to 5
6 rounds up to 10
7 rounds up to 10
8 rounds up to 10
9 rounds up to 10
10 rounds up to 10
After a fair bit of experimentation, I ended up with the following, but it doesn't work properly.
This code rounds DOWN, so 9 rounds down to 5. Anyone know how to make it round UP?
for(int i = 0; i < 40; i++)
int temp = (int) (Math.ceil(i/5)*5);
System.out.println("I = " + i + ", rounded = " + temp);