RubyMoney/money · error · Money::UndefinedSmallestDenomination

Smallest denomination of this currency is not defined

Error message

Smallest denomination of this currency is not defined

What it means

Error "Smallest denomination of this currency is not defined" thrown in RubyMoney/money.

Source

Thrown at lib/money/money.rb:86

  # @return [BigDecimal] when infinite_precision is true
  #
  # @see infinite_precision
  def round_to_nearest_cash_value
    warn "[DEPRECATION] `round_to_nearest_cash_value` is deprecated - use " \
         "`to_nearest_cash_value.fractional` instead"

    to_nearest_cash_value.fractional
  end

  # Round a given amount of money to the nearest possible money in cash value.
  # For example, in Swiss franc (CHF), the smallest possible amount of cash
  # value is CHF 0.05. Therefore, this method rounds CHF 0.07 to CHF 0.05, and
  # CHF 0.08 to CHF 0.10.
  #
  # @return [Money]
  def to_nearest_cash_value
    unless currency.smallest_denomination
      raise UndefinedSmallestDenomination,
            "Smallest denomination of this currency is not defined"
    end

    fractional = as_d(@fractional)
    smallest_denomination = as_d(currency.smallest_denomination)
    rounded_value =
      (fractional / smallest_denomination)
      .round(0, self.class.rounding_mode) * smallest_denomination

    dup_with(fractional: return_value(rounded_value))
  end

  # @!attribute [r] currency
  #   @return [Currency] The money's currency.
  # @!attribute [r] bank
  #   @return [Money::Bank::Base] The +Money::Bank+-based object which currency
  #     exchanges are performed with.

View on GitHub (pinned to 26e2829c34)

When it happens

Trigger: Thrown at lib/money/money.rb:86 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/1c7b8ac3b77fc03f. Report an issue: GitHub.