protected override void Calculate(decimal balance, int months, decimal rates) { decimal baseAmount = Round(balance / months), totalAmount = 0, totalInterest = 0; for (int month = months; month >= 1; month--) { var monthRate = GetMonthRate(rates); var interest = Round(balance * monthRate); var monthAmount = baseAmount + interest; balance -= baseAmount; if (month == 1 && balance != 0) { baseAmount += balance; monthAmount += balance; balance = 0; } totalAmount += monthAmount; totalInterest += interest; CalculateTable calTable = new CalculateTable(); calTable.ID = months - month + 1; calTable.monthAmount = monthAmount.ToString("0.00"); calTable.baseAmount = baseAmount.ToString("0.00"); calTable.interest = interest.ToString("0.00"); calTable.balance = balance.ToString("0.00"); lstCalculateTable.Add(calTable); } }
protected override void Calculate(decimal balance, int months, decimal rates) { decimal baseAmount = 0; decimal monthRate0 = decimal.MinValue, monthAmount = decimal.MinValue; for (int month = months; month >= 1; month--) { var monthRate = GetMonthRate(rates); var interest = Round(balance * monthRate); if (monthRate0 != monthRate) { monthAmount = GetMonthAmount(balance, monthRate0 = monthRate, month); } baseAmount = monthAmount - interest; balance -= baseAmount; if (month == 1 && balance != 0) { baseAmount += balance; interest -= balance; balance = 0; } //Table.Rows.Add(new object[] { months - month + 1, monthAmount, baseAmount, interest, balance }); CalculateTable calTable = new CalculateTable(); calTable.ID = months - month + 1; calTable.monthAmount = monthAmount.ToString("0.00"); calTable.baseAmount = baseAmount.ToString("0.00"); calTable.interest = interest.ToString("0.00"); calTable.balance = balance.ToString("0.00"); lstCalculateTable.Add(calTable); } }
protected override void Calculate(decimal balanceGJJ, decimal balanceSY, int months , decimal ratesGJJ, decimal ratesSY) { decimal baseAmountGJJ = 0, baseAmountSY = 0; decimal monthRate0GJJ = decimal.MinValue, monthRate0SY = decimal.MinValue, monthAmountGJJ = decimal.MinValue, monthAmountSY = decimal.MinValue; for (int month = months; month >= 1; month--) { var monthRateGJJ = GetMonthRate(ratesGJJ); var interestGJJ = Round(balanceGJJ * monthRateGJJ); if (monthRate0GJJ != monthRateGJJ) { monthAmountGJJ = GetMonthAmount(balanceGJJ, monthRate0GJJ = monthRateGJJ, month); } baseAmountGJJ = monthAmountGJJ - interestGJJ; balanceGJJ -= baseAmountGJJ; if (month == 1 && balanceGJJ != 0) { baseAmountGJJ += balanceGJJ; interestGJJ -= balanceGJJ; balanceGJJ = 0; } var monthRateSY = GetMonthRate(ratesSY); var interestSY = Round(balanceSY * monthRateSY); if (monthRate0SY != monthRateSY) { monthAmountSY = GetMonthAmount(balanceSY, monthRate0SY = monthRateSY, month); } baseAmountSY = monthAmountSY - interestSY; balanceSY -= baseAmountSY; if (month == 1 && balanceSY != 0) { baseAmountSY += balanceSY; interestSY -= balanceSY; balanceSY = 0; } var monthAmount = monthAmountGJJ + monthAmountSY; var interest = interestGJJ + interestSY; var balance = balanceGJJ + balanceSY; CalculateTable calTable = new CalculateTable(); calTable.ID = months - month + 1; calTable.monthAmount = monthAmount.ToString("0.00"); calTable.baseAmount = (baseAmountGJJ + baseAmountSY).ToString("0.00"); //baseAmount.ToString("0.00"); calTable.interest = interest.ToString("0.00"); calTable.balance = balance.ToString("0.00"); lstCalculateTable.Add(calTable); } }
protected override void Calculate(decimal balanceGJJ, decimal balanceSY, int months, decimal ratesGJJ, decimal ratesSY) { decimal baseAmountSY = Round(balanceSY / months), totalAmountSY = 0, totalInterestSY = 0; decimal baseAmountGJJ = Round(balanceGJJ / months), totalAmountGJJ = 0, totalInterestGJJ = 0; decimal totalAmount = 0, totalInterest = 0; for (int month = months; month >= 1; month--) { var monthRateSY = GetMonthRate(ratesSY); var interestSY = Round(balanceSY * monthRateSY); var monthAmountSY = baseAmountSY + interestSY; balanceSY -= baseAmountSY; var monthRateGJJ = GetMonthRate(ratesGJJ); var interestGJJ = Round(balanceGJJ * monthRateGJJ); var monthAmountGJJ = baseAmountGJJ + interestGJJ; balanceGJJ -= baseAmountGJJ; var monthAmount = monthAmountSY + monthAmountGJJ; var baseAmount = baseAmountSY + baseAmountGJJ; var interest = interestSY + interestGJJ; var balance = balanceSY + balanceGJJ; if (month == 1 && balanceSY != 0) { baseAmountSY += balanceSY; monthAmountSY += balanceSY; balanceSY = 0; baseAmountGJJ += balanceGJJ; monthAmountGJJ += balanceGJJ; balanceSY = 0; } totalAmountSY += monthAmountSY; totalInterestSY += interestSY; totalAmountGJJ += monthAmountGJJ; totalInterestGJJ += interestGJJ; totalAmount = totalAmountSY + totalAmountGJJ; totalInterest = totalInterestSY + totalInterestGJJ; CalculateTable calTable = new CalculateTable(); calTable.ID = months - month + 1; calTable.monthAmount = monthAmount.ToString("0.00"); calTable.baseAmount = baseAmount.ToString("0.00"); calTable.interest = interest.ToString("0.00"); calTable.balance = balance.ToString("0.00"); lstCalculateTable.Add(calTable); } }