Rounding to the nearest half (NOT the nearest whole)
I think that Math.round(num * 2) / 2.0f
should solve the rounding to the nearest half problem:
Math.round(3.9 * 2) / 2.0f == 8 / 2.0f = 4.0
Math.round(3.6 * 2) / 2.0f == 7 / 2.0f = 3.5
Math.round(3.1 * 2) / 2.0f == 6 / 2.0f = 3.0
rounding to any fraction f:
double f = 0.5;
double rounded = f * Math.round(x/f);
Subtract, round and add...
Math.round(value - 0.5) + 0.5
Another working way mentioned in question's comments:
Math.floor(value) + 0.5