A succinct solution:
public static double round(double value, int precision) {
int scale = (int) Math.pow(10, precision);
return (double) (Math.round(value * scale) / scale;scale);
}
See also, https://stackoverflow.com/a/22186845/212950 Thanks to jpdymond for offering this.
Edit: Added round brackets. Casts the whole result to double, not the first argument only!