でこれを計算する方法。
public decimal CalculatePayment()
{
DateTime lastPaymentDueDate = new DateTime(2016, 7, 27);
DateTime thisPaymentDate = new DateTime(2016, 10, 27);
decimal policy = 10000.0M;
decimal mthFee = 5000.0M;
decimal mthFine = policy * 2.0M/100.0M;
decimal payAmount = 0.0M;
DateTime nextPaymentDueDate = lastPaymentDueDate.AddMonths(1);
int thisPayJulian = (int)thisPaymentDate.ToOADate();
int nextDueJulian = (int)nextPaymentDueDate.ToOADate();
if (thisPayJulian < nextDueJulian)
{
//nothing to pay
return payAmount;
}
while (thisPayJulian - nextDueJulian > 15)
{
//deal with late payments
payAmount += mthFine + mthFee;
nextPaymentDueDate = nextPaymentDueDate.AddMonths(1);
nextDueJulian = (int)nextPaymentDueDate.ToOADate();
}
if (thisPayJulian >= nextDueJulian)
{
//deal with regular payments
payAmount += mthFee;
}
return payAmount;
}
は明らかに現実の世界では、lastPaymentDueDate、thisPaymentDate、および政策、料金及び罰金割合は、すべてのように、ここでのパラメータではなく、固定変数であるだろうが、私はあなたのアイデアを得る願っています。
しかし、他のコメントをもう一度繰り返す必要があります。一般的に、あなたがやったよりもむしろ自分のコードをもっと表示しないと、人々はあまり助けてくれることはありません。
あなたは新しいstackoverflowを希望しています。これを見てくださいhttp://stackoverflow.com/help/how-to-ask –
また、あなたが試したこととどこに問題があるかを示してください。 –
if(extdate