コード例 #1
0
        public IEnumerable <Money> Allocate(Money money, RatioArray ratios)
        {
            var     currency = money.Currency;
            decimal total    = money.Amount;

            int     len  = ratios.Length;
            var     dist = new decimal[len];
            decimal last = total;

            for (var i = 0; i < len - 1; i++)
            {
                decimal amount = ratios[i] * total;
                last -= amount;
                yield return(new Money(amount, currency));
            }

            yield return(new Money(last, currency));
        }
コード例 #2
0
        public IEnumerable <Money> Allocate(Money money, RatioArray ratios)
        {
            var     currency      = money.Currency;
            decimal total         = money.Amount;
            int     decimalPlaces = currency.DecimalPlaces;

            int     len  = ratios.Length;
            var     dist = new decimal[len];
            decimal last = total;

            for (var i = 0; i < len - 1; i++)
            {
                decimal amount = RoundingAdjuster.Round(ratios[i] * total, decimalPlaces);
                last -= amount;
                yield return(Money.FromMajor(amount, currency));
            }

            yield return(Money.FromMajor(last, currency, RoundingAdjuster));
        }