public function exactlyDividedBy($that) : BigDecimal
    {
        $that = BigDecimal::of($that);

        if ($that->value === '0') {
            throw DivisionByZeroException::divisionByZero();
        }

        $this->scaleValues($this, $that, $a, $b);

        $d = \rtrim($b, '0');
        $scale = \strlen($b) - \strlen($d);

        $calculator = Calculator::get();

        foreach ([5, 2] as $prime) {
            for (;;) {
                $lastDigit = (int) $d[-1];

                if ($lastDigit % $prime !== 0) {
                    break;
                }

                $d = $calculator->divQ($d, (string) $prime);
                $scale++;
            }
        }

        return $this->dividedBy($that, $scale)->stripTrailingZeros();
    }
public function exactlyDividedBy($that) : BigDecimal
    {
        $that = BigDecimal::of($that);

        if ($that->value === '0') {
            throw DivisionByZeroException::divisionByZero();
        }

        $this->scaleValues($this, $that, $a, $b);

        $d = \rtrim($b, '0');
        $scale = \strlen($b) - \strlen($d);

        $calculator = Calculator::get();

        foreach ([5, 2] as $prime) {
            for (;;) {
                $lastDigit = (int) $d[-1];

                if ($lastDigit % $prime !== 0) {
                    break;
                }

                $d = $calculator->divQ($d, (string) $prime);
                $scale++;
            }
        }

        return $this->dividedBy($that, $scale)->stripTrailingZeros();
    }
public function exactlyDividedBy ( $ that ) : BigDecimal { $ that = BigDecimal :: of ( $ that ) ; if ( $ that -> value === '0' ) { throw DivisionByZeroException :: divisionByZero ( ) ; } $ this -> scaleValues ( $ this , $ that , $ a , $ b ) ; $ d = \ rtrim ( $ b , '0' ) ; $ scale = \ strlen ( $ b ) - \ strlen ( $ d ) ; $ calculator = Calculator :: get ( ) ; foreach ( [ 5 , 2 ] as $ prime ) { for ( ; ; ) { $ lastDigit = ( int ) $ d [ - 1 ] ; if ( $ lastDigit % $ prime !== 0 ) { break ; } $ d = $ calculator -> divQ ( $ d , ( string ) $ prime ) ; $ scale ++ ; } } return $ this -> dividedBy ( $ that , $ scale ) -> stripTrailingZeros ( ) ; }
Returns the exact result of the division of this number by the given one.

The scale of the result is automatically calculated to fit all the fraction digits.

@param BigNumber|number|string $that The divisor. Must be convertible to a BigDecimal.

@return BigDecimal The result.

@throws MathException If the divisor is not a valid number, is not convertible to a BigDecimal, is zero,
or the result yields an infinite number of digits.
Returns the exact result of the division of this number by the given one .