RubyMoney/money · error · ZeroDivisionError

divided by Money(0)

Error message

divided by Money(0)

What it means

Error "divided by Money(0)" thrown in RubyMoney/money.

Source

Thrown at lib/money/money/arithmetic.rb:207

    # Divides the monetary value with the given number and returns a new +Money+
    # object with this monetary value and the same currency.
    # Can also divide by another +Money+ object to get a ratio.
    #
    # +Money/Numeric+ returns +Money+. +Money/Money+ returns +Float+.
    #
    # @param [Money, Numeric] value Number to divide by.
    #
    # @return [Money] The resulting money if you divide Money by a number.
    # @return [Float] The resulting number if you divide Money by a Money.
    #
    # @example
    #   Money.new(100) / 10            #=> #<Money @fractional=10>
    #   Money.new(100) / Money.new(10) #=> 10.0
    #
    def /(other)
      if other.is_a?(self.class)
        exchanged = other.exchange_to(currency)
        raise ZeroDivisionError, "divided by Money(0)" if exchanged.zero?

        fractional / as_d(exchanged.fractional).to_f
      else
        raise TypeError, "Can not divide by Money" if other.is_a?(CoercedNumeric)

        other = as_d(other)
        raise ZeroDivisionError, "divided by zero" if other.zero?

        dup_with(fractional: fractional / other)
      end
    end

    # Synonym for +#/+.
    #
    # @param [Money, Numeric] value Number to divide by.
    #
    # @return [Money] The resulting money if you divide Money by a number.
    # @return [Float] The resulting number if you divide Money by a Money.

View on GitHub (pinned to 26e2829c34)

When it happens

Trigger: Thrown at lib/money/money/arithmetic.rb:207 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of RubyMoney/money@26e2829c34 (2026-08-23). Data as JSON: /api/errors/403a40efac4125d8. Report an issue: GitHub.