本文整理汇总了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;
}