public function dividedBy($that, int $scale = null, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
    {
        $that = BigDecimal::of($that);

        if ($that->isZero()) {
            throw DivisionByZeroException::divisionByZero();
        }

        if ($scale === null) {
            $scale = $this->scale;
        } elseif ($scale < 0) {
            throw new \InvalidArgumentException('Scale cannot be negative.');
        }

        if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) {
            return $this;
        }

        $p = $this->valueWithMinScale($that->scale + $scale);
        $q = $that->valueWithMinScale($this->scale - $scale);

        $result = Calculator::get()->divRound($p, $q, $roundingMode);

        return new BigDecimal($result, $scale);
    }
public function dividedBy($that, int $scale = null, int $roundingMode = RoundingMode::UNNECESSARY) : BigDecimal
    {
        $that = BigDecimal::of($that);

        if ($that->isZero()) {
            throw DivisionByZeroException::divisionByZero();
        }

        if ($scale === null) {
            $scale = $this->scale;
        } elseif ($scale < 0) {
            throw new \InvalidArgumentException('Scale cannot be negative.');
        }

        if ($that->value === '1' && $that->scale === 0 && $scale === $this->scale) {
            return $this;
        }

        $p = $this->valueWithMinScale($that->scale + $scale);
        $q = $that->valueWithMinScale($this->scale - $scale);

        $result = Calculator::get()->divRound($p, $q, $roundingMode);

        return new BigDecimal($result, $scale);
    }
public function dividedBy ( $ that , int $ scale = null , int $ roundingMode = RoundingMode :: UNNECESSARY ) : BigDecimal { $ that = BigDecimal :: of ( $ that ) ; if ( $ that -> isZero ( ) ) { throw DivisionByZeroException :: divisionByZero ( ) ; } if ( $ scale === null ) { $ scale = $ this -> scale ; } elseif ( $ scale < 0 ) { throw new \ InvalidArgumentException ( 'Scale cannot be negative.' ) ; } if ( $ that -> value === '1' && $ that -> scale === 0 && $ scale === $ this -> scale ) { return $ this ; } $ p = $ this -> valueWithMinScale ( $ that -> scale + $ scale ) ; $ q = $ that -> valueWithMinScale ( $ this -> scale - $ scale ) ; $ result = Calculator :: get ( ) -> divRound ( $ p , $ q , $ roundingMode ) ; return new BigDecimal ( $ result , $ scale ) ; }
Returns the result of the division of this number by the given one, at the given scale.

@param BigNumber|number|string $that         The divisor.
@param int|null                $scale        The desired scale, or null to use the scale of this number.
@param int                     $roundingMode An optional rounding mode.

@return BigDecimal

@throws \InvalidArgumentException If the scale or rounding mode is invalid.
@throws MathException             If the number is invalid, is zero, or rounding was necessary.
Returns the result of the division of this number by the given one at the given scale .