class Money

def round_to_nearest_cash_value

Other tags:
    See: infinite_precision -

Returns:
  • (BigDecimal) - when infinite_precision is true
  • (Integer) - when infinite_precision is false
def round_to_nearest_cash_value
  unless self.currency.smallest_denomination
    raise UndefinedSmallestDenomination, 'Smallest denomination of this currency is not defined'
  end
  fractional = as_d(@fractional)
  smallest_denomination = as_d(self.currency.smallest_denomination)
  rounded_value = (fractional / smallest_denomination).round(0, self.class.rounding_mode) * smallest_denomination
  return_value(rounded_value)
end