lib/money/money.rb
# Split money amongst parties evenly without loosing pennies.
#
# @param [2] number of parties.
#
# @return [Array<Money, Money, Money>]
#
# @example
#   Money.new(100, "USD").split(3) #=> [Money.new(34), Money.new(33), Money.new(33)]
Split money amongst parties evenly without loosing pennies.
Split money amongst parties evenly without loosing pennies .
def split(num)
    raise ArgumentError, "need at least one party" if num < 1
    if self.class.infinite_precision
      amt = self.div(BigDecimal(num.to_s))
      return 1.upto(num).map{amt}
    end
    low = Money.new(cents / num, self.currency)
    high = Money.new(low.cents + 1, self.currency)
    remainder = cents % num
    result = []
    num.times do |index|
      result[index] = index < remainder ? high : low
    end
    result
  end
def split ( num ) raise ArgumentError , "need at least one party" if num < 1 if self . class . infinite_precision amt = self . div ( BigDecimal ( num . to_s ) ) return 1 . upto ( num ) . map { amt } end low = Money . new ( cents / num , self . currency ) high = Money . new ( low . cents + 1 , self . currency ) remainder = cents % num result = [ ] num . times do | index | result [ index ] = index < remainder ? high : low end result end
Split money amongst parties evenly without loosing pennies.
Split money amongst parties evenly without loosing pennies .
None
Array<Money, Money, Money>
num
<not_specific>
<not_specific>
number of parties.
number of parties .
example
None