code: public static double round(double x, int precision) {
      double power = Math.pow(10.0, precision);
      return round(x * power) / power;
    }
docs: Round a double to the given number of decimal places,
  rounding to the nearest value via conventional rules (5 rounds up, 49
  rounds down).
  E.g. round(3.1416, 2) == 3.14, round(431.5, -2) == 400,
  round(431.5, 0) = 432