当前位置: 首页>>代码示例>>C#>>正文


C# Currency.Round方法代码示例

本文整理汇总了C#中Currency.Round方法的典型用法代码示例。如果您正苦于以下问题:C# Currency.Round方法的具体用法?C# Currency.Round怎么用?C# Currency.Round使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Currency的用法示例。


在下文中一共展示了Currency.Round方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Amortize

        /// <summary>
        /// Computes the amortization schedule for this loan, taking into account one or more additional payments.
        /// For 1-based payment number n, the AdditionalPayment object in additionalPayments with Ordinal == n 
        /// is added to the AdditionalPayment member of that payment, and the amortization schedule is computed taking this into account.
        /// 
        /// </summary>
        /// <returns></returns>
        public List<Payment> Amortize(Currency currency, IEnumerable<AdditionalPayment> additionalPayments)
        {
            var periodPaymentAmount = currency.Round(ComputePeriodicPayment());
            var payments = new List<Payment>();

            var remainingPrincipal = Principal;
            for (var idx = 1; idx <= NumPayments; idx++)
            {
                var interest = currency.Round(remainingPrincipal * InterestRate);
                var principal = periodPaymentAmount - interest;
                var additionalPayment = AdditionalPayment;

                //Add the payment-specific additional payment if one was specified
                if (additionalPayments != null)
                {
                    var extraPayment = (additionalPayments.Where(x => x.Ordinal == idx)).SingleOrDefault();
                    if (extraPayment != null)
                    {
                        additionalPayment += extraPayment.Amount;
                    }
                }

                if (idx < NumPayments)
                {
                    //This is not the last payment.  Subtract the princiapl and any additional payment amount, unless
                    //that's more than the remaining principal
                    if (remainingPrincipal > principal)
                    {
                        remainingPrincipal -= principal;
                    }
                    else
                    {
                        principal = remainingPrincipal;
                        remainingPrincipal = 0;
                    }

                    if (remainingPrincipal > additionalPayment)
                    {
                        remainingPrincipal -= additionalPayment;
                    }
                    else
                    {
                        additionalPayment = remainingPrincipal;
                        remainingPrincipal = 0;
                    }
                }
                else
                {
                    //This is the last payment, so it must include all remaining principal
                    principal = remainingPrincipal;
                    remainingPrincipal = 0;

                    //No additional payment is possible on the last payment, since all the remaining principal is due at the point
                    additionalPayment = 0;
                }

                payments.Add(
                    new Payment()
                    {
                        Ordinal = idx,
                        Principal = principal,
                        Interest = interest,
                        AdditionalPayment = additionalPayment,
                        OutstandingPrincipal = remainingPrincipal
                    }
                    );

                if (remainingPrincipal == 0)
                {
                    //All paid off, so even if this wasn't the last of the expected payments, 
                    //the loan is no longer outstanding
                    break;
                }
            }

            return payments;
        }
开发者ID:anelson,项目名称:mortcalc.net,代码行数:84,代码来源:AmortizedLoan.cs


注:本文中的Currency.Round方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。