C # Implementation of equal and principal-interest method, monthly interest-based repayment method, one-time debt-servicing method

Source: Internet
Author: User

If you are knowledgeable, it will be useful, as follows:

void Main ()
{
var x = Dengebenxi.compute (11111, 12, 3);
X.dump ();
var y = Anyuefuxidaoqihuanben.compute (11111, 12, 3);
Y.dump ();
var z = yicixinghuanbenfuxi.compute (11111, 12, 3);
Z.dump ();
}
public class Dengebenxi
{
<summary>
Equal and principal method
</summary>
<param name= "Amountt" > Investment amount </param>
<param name= "Yearrate" > Annual interest Rate </param>
<param name= "MONTHSX" > Investment period, Unit: Month </param>
<returns></returns>
public static list<backunit> Compute (double amount, double yearrate, int months)
{

var monthrate = (yearrate)/1200.0; Annual interest rate converted to monthly interest rate
var datalist = new list<backunit> ();
var i = 0;
var a = 0.0; Repayment of principal and interest
var b = 0.0; Repayment of Interest
var c = 0.0; Repayment of Principal
Interest income
var totalrateincome =
(Amount * months * monthrate * MATH.POW ((1 + monthrate), months)/(Math.pow ((1 + monthrate), months)-1)-Amount;
var totalincome = totalrateincome + amount;
var d = amount + totalrateincome; Remaining Principal

Totalrateincome = Math.Round (totalrateincome * 100)/100;//total Interest paid
Totalincome = Math.Round (totalincome * 100)/100;
A = totalincome/months; Monthly repayment principal and interest
A = Math.Round (A * 100)/100;//monthly repayment principal and interest

for (i = 1; I <= months; i++)
{
b = (Amount * monthrate * (Math.pow ((1 + monthrate), months)-Math.pow ((1 + monthrate), (i-1)))/(Math.pow ((1 + month Rate), months)-1);
b = Math.Round (b * 100)/100;
c = A-B;
c = Math.Round (c * 100)/100;
D = d-a;
D = Math.Round (d * 100)/100;
if (i = = months)
{
c = C + D;
b = b-d;
c = Math.Round (c * 100)/100;
b = Math.Round (b * 100)/100;
d = 0;
}

var unit = new Backunit ();
Unit. Number = i;//Period
Unit. Totalrate = totalrateincome;//Total Interest
Unit. Totalmoney = totalincome;//Total Repayment
Unit. A = a;//Repayment of principal and interest somenumber.tostring ("N2");
Unit. B = b;//Interest Payment
Unit. C = c;//Repayment of Principal
Unit. D = d;//remaining Principal
DataList. ADD (unit);
}

return DataList;
}
}

public class Anyuefuxidaoqihuanben
{
<summary>
Repayment by monthly interest due
</summary>
<param name= "Amount" > Investment amount </param>
<param name= "Yearrate" > Annual interest Rate </param>
<param name= "months" > Investment period, Unit: Month </param>
<returns></returns>
public static list<backunit> Compute (double amount, double yearrate, int months)
{
var datalist = new list<backunit> ();     New Array (Deadline); //

Double rateincome = Amount * yearrate/100 * (months/12.0);
Double Rateincomeeve = (rateincome/months);

var total = amount + rateincome;

for (var i = 1; i < months; i++)
{
var unit = new Backunit ();
Unit. Number = i;//Period
Unit. Totalrate = Rateincome;//math.round ((Amount + totalrate) * 100)/100;//Total Interest
Unit. Totalmoney = total;//totalrate;//Total Repayment
Unit. A = rateincomeeve;//Repayment of principal and interest somenumber.tostring ("N2");
Unit. B = rateincomeeve;//Interest Payment
Unit. C = 0;//Repayment of Principal
Unit. D = Amount * 1 + rateincome * 1-rateincomeeve * i;//remaining Principal
DataList. ADD (unit);
}

DataList. ADD (New Backunit () {
Number= months,
Totalrate = Rateincome,
Totalmoney = Total,
A = amount + Rateincomeeve,
B = Rateincomeeve,
C = Amount,
D = 0
});
return DataList;
}
}

public class Yicixinghuanbenfuxi
{
<summary>
One-time debt servicing
</summary>
<param name= "Amount" > Investment amount </param>
<param name= "Yearrate" > Annual interest Rate </param>
<param name= "months" > Investment period, Unit: Month </param>
<returns></returns>
public static Backunit Compute (double amount, double yearrate, int months)
{
Backunit unit = new Backunit ();
var rate = Yearrate;
var rateincome = amount * rate/100 * (months/12.0);
var totalincome = amount + rateincome;

Unit. Number = 1;//Period
Unit. Totalrate = Rateincome;//math.round ((Amount + totalrate) * 100)/100;//Total Interest
Unit. Totalmoney = totalincome;//totalrate;//Total Repayment
Unit. A = totalincome;//Repayment of principal and interest somenumber.tostring ("N2");
Unit. B = rateincome;//Interest Payment
Unit. C = 0;//Repayment of Principal
Unit. D = 0;//remaining Principal
return unit;
}
}

public class Backunit
{
Current number of periods
public int number {get; set;}
Total Interest
Public double totalrate {get; set;}
Total repayment
Public double Totalmoney {get; set;}
This period should also be all
Public double A {get; set;}
Interest payable in this period
Public double B {get; set;}
This period should also be the principal
Public double C {get; set;}
Remaining principal in this period
Public double D {get; set;}
}

The following is the result of the operation:

Come with one of the online test addresses I wrote: Http://p2p.tminji.com/phome/mockcompute.

C # Implementation of equal and principal-interest method, monthly interest-based repayment method, one-time debt-servicing method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.