code: public static BigDecimal decimalRound(BigDecimal number, int numDigits, RoundingMode rounding) {
          BigDecimal rounded = number.setScale(numDigits, rounding);
  
          if (numDigits < 0) {
              rounded = rounded.setScale(0, BigDecimal.ROUND_UNNECESSARY);
          }
  
          return rounded;
      }
docs: Rounding for decimals with support for negative digits