code: public static double round(double x, int decimal) {
          if (decimal < 0) {
              return round(x / pow(10, -decimal)) * pow(10, -decimal);
          } else {
              return round(x * pow(10, decimal)) / pow(10, decimal);
          }
      }
docs: Round a double vale to given digits such as 10^n, where n is a positive
  or negative integer.