code: public static double round(double d, int p) {
  
          double f = Math.pow(10., p);
  
          return Math.round(d * f) / f;
      }
docs: Returns the given <code>double</code> value, rounded to the given
  <code>int</code> places right of the decimal point. If
  the supplied rounding place value is negative, rounding is performed
  to the left of the decimal point, using its magnitude (absolute value).
  @param d the value to be rounded
  @param p the rounding place value
  @return <code>d</code> rounded