public Allocation Allocate(RatioCollection ratios) { Money[] results = Money.Zero(_currency, ratios.Count); //allocated = Money.Zero(_currency); for (var i = 0; i < ratios.Count; i++) { var share = ratios[i].ApplyTo(_toAllocate.Amount); share = _currency.Round(share); results[i] = new Money(share, _currency); } return(new Allocation(_toAllocate, results)); }
public Money[] Allocate(RatioCollection ratios, out Money allocated) { var results = initResults(ratios.Count); allocated = Money.Zero(_currency); for (var i = 0; i < ratios.Count; i++) { var share = ratios[i].ApplyTo(_toAllocate.Amount); share = _currency.Round(share); results[i] = new Money(share, _currency); allocated += results[i]; } return(results); }
public static Allocation Allocate(this Money money, RatioCollection ratios, IRemainderAllocator allocator) { Guard.AgainstNullArgument(nameof(ratios), ratios); if (money.notEnoughToAllocate()) { return(Allocation.Zero(money, ratios.Count)); } Allocation allocated = new ProRataAllocator(money) .Allocate(ratios); allocated = money.allocateRemainderIfNeeded(allocator, allocated); return(allocated); }
public static Allocation Allocate(this Money money, RatioCollection ratios) { return(money.Allocate(ratios, RemainderAllocator.FirstToLast)); }