code: public BigDecimal divideToIntegralValue(BigDecimal divisor) {
          // Calculate preferred scale
          int preferredScale = saturateLong((long) this.scale - divisor.scale);
          if (this.compareMagnitude(divisor) < 0) {
              // much faster when this << divisor
              return zeroValueOf(preferredScale);
          }
  
          if (this.signum() == 0 && divisor.signum() != 0)
              return this.setScale(preferredScale, ROUND_UNNECESSARY);
  
          // Perform a divide with enough digits to round to a correct
          // integer value; then remove any fractional digits
  
          int maxDigits = (int)Math.min(this.precision() +
                                        (long)Math.ceil(10.0*divisor.precision()/3.0) +
                                        Math.abs((long)this.scale() - divisor.scale()) + 2,
                                        Integer.MAX_VALUE);
          BigDecimal quotient = this.divide(divisor, new MathContext(maxDigits,
                                                                     RoundingMode.DOWN));
          if (quotient.scale > 0) {
              quotient = quotient.setScale(0, RoundingMode.DOWN);
              quotient = stripZerosToMatchScale(quotient.intVal, quotient.intCompact, quotient.scale, preferredScale);
          }
  
          if (quotient.scale < preferredScale) {
              // pad with zeros if necessary
              quotient = quotient.setScale(preferredScale, ROUND_UNNECESSARY);
          }
  
          return quotient;
      }
docs: Returns a {@code BigDecimal} whose value is the integer part
  of the quotient {@code (this / divisor)} rounded down.  The
  preferred scale of the result is {@code (this.scale() -
  divisor.scale())}.
  
  @param  divisor value by which this {@code BigDecimal} is to be divided.
  @return The integer part of {@code this / divisor}.
  @throws ArithmeticException if {@code divisor==0}
  @since  1.5