c#实现房贷计算的方法源码-创新互联
publ
/// 商业贷款-根据面积,单价计算
///
/// 单价
/// 面积
/// 按揭成数
/// 按揭年数
/// 年利率
/// 还款方式
///
private string returnResult(double unitPrice, double acreage, double mortgage, int countYears, double lilv, string paymentType)
{
StringBuilder json = new StringBuilder();
double newlilv = lilv / 100/12;//月利率
double purchase=0;//房款总额;
double Loan=0;//贷款总额
double monthlypayments=0;//平均月供
double Total=0;//还款总额
double Interest=0;//总利息
double Shoufu=0;//首付
switch (paymentType.Trim())
{
case "debx"://等额本息
purchase = Math.Round(unitPrice * acreage,2);
Loan = Math.Round(purchase * mortgage,2);
monthlypayments =Math.Round((Loan * newlilv * Math.Pow(1 + newlilv, countYears * 12)) / (Math.Pow(1 + newlilv, countYears * 12) - 1),2);
Total = Math.Round(monthlypayments * countYears * 12,2);
Interest = Math.Round(Total - Loan,2);
Shoufu = Math.Round(purchase - Loan,2);
json.Append("{"purchase":"" + purchase.ToString() + "","Loan":"" + Loan.ToString() + "","Forthemonth":"" + monthlypayments.ToString() + "","Total":"" + Total.ToString() + "","Interest":"" + Interest.ToString() + "","Shoufu":"" + Shoufu.ToString() + "","months":"" + countYears * 12 +"(月)"+ ""}");
break;
case "debj"://等额本金
purchase = Math.Round(unitPrice * acreage,2);
Loan =Math.Round(purchase * mortgage,2);
string monthsPay = string.Empty;
for (int i = 0; i < countYears * 12; i++)
{
monthlypayments =Loan / (countYears * 12) + (Loan - Loan / (countYears * 12) * i) * newlilv;
monthsPay +="第"+ (i + 1) + "个月," + Math.Round(monthlypayments,2) + "(元)\r\n";//月均金额
Total =monthlypayments + Total;//还款总额
}
Interest =Math.Round(Total - Loan,2);
Shoufu = Math.Round(purchase - Loan,2);
json.Append("{"purchase":"" + purchase.ToString() + "","Loan":"" + Loan.ToString() + "","Forthemonth":"" + monthsPay.ToString() + "","Total":"" + Math.Round(Total,2) + "","Interest":"" + Interest.ToString() + "","Shoufu":"" + Shoufu.ToString() + "","months":"" + countYears * 12 + "(月)" + ""}");
break;
}
return json.ToString();
}
///
/// 商业贷款-根据贷款总额计算
///
/// 贷款总额
/// 按揭年数
/// 年利率
/// 还款方式
///
private string returnResult(double loanceiling, int countYears, double lilv, string paymentType)
{
StringBuilder json = new StringBuilder();
double newlilv = lilv / 100 / 12;//月利率
double Loan = loanceiling;//贷款总额
double monthlypayments = 0;//平均月供
double Total = 0;//还款总额
double Interest = 0;//总利息
switch (paymentType.Trim())
{
case "debx"://等额本息
monthlypayments = Math.Round((Loan * newlilv * Math.Pow(1 + newlilv, countYears * 12)) / (Math.Pow(1 + newlilv, countYears * 12) - 1), 2);
Total = Math.Round(monthlypayments * countYears * 12, 2);
Interest = Math.Round(Total - Loan, 2);
json.Append("{"purchase":"略","Loan":"" + Loan.ToString() + "","Forthemonth":"" + monthlypayments.ToString() + "","Total":"" + Total.ToString() + "","Interest":"" + Interest.ToString() + "","Shoufu":"0","months":"" + countYears * 12 + "(月)"+""}");
break;
case "debj"://等额本金
string monthsPay = string.Empty;
for (int i = 0; i < countYears * 12; i++)
{
monthlypayments =Loan / (countYears * 12) + (Loan - Loan / (countYears * 12) * i) * newlilv;
monthsPay +="第"+ (i + 1) + "个月," + Math.Round(monthlypayments,2) + "(元)\r\n";//月均金额
Total =monthlypayments + Total;//还款总额
}
Interest = Math.Round(Total - Loan, 2);
json.Append("{"purchase":"略","Loan":"" + Math.Round(Loan,2) + "","Forthemonth":"" + monthsPay.ToString() + "","Total":"" + Math.Round(Total, 2) + "","Interest":"" + Interest.ToString() + "","Shoufu":"0","months":"" + countYears * 12 + "(月)" + ""}");
break;
}
return json.ToString();
}
///
/// 组合型贷款
///
/// 商业贷款额
/// 商业贷款利率(年利率)
/// 公积金贷款额
/// 公积金贷款额利率(年利率)
/// 贷款期限
/// 还款方式
///
private string returnResult(double syx_loanceiling, double sy_lilvValues, double gjj_loanceiling,double gjj_lilvValues, int countYears,string paymentType)
{
StringBuilder json = new StringBuilder();
double sy_newlilv = sy_lilvValues / 100 / 12;//月利率
double sy_Loan = syx_loanceiling;//贷款总额
double sy_monthlypayments = 0;//平均月供
double sy_Total = 0;//商业还款总额
double sy_Interest = 0;//商业贷款利息
double gjj_newlilv = gjj_lilvValues / 100 / 12;//月利率
double gjj_Loan = gjj_loanceiling;//贷款总额
double gjj_monthlypayments = 0;//平均月供
double gjj_Total = 0;//公积金还款总额
double gjj_Interest = 0;//公积金贷款利息
switch (paymentType.Trim())
{
case "debx"://等额本息
//商业贷款
sy_monthlypayments = Math.Round((sy_Loan * sy_newlilv * Math.Pow(1 + sy_newlilv, countYears * 12)) / (Math.Pow(1 + sy_newlilv, countYears * 12) - 1), 2);
sy_Total = Math.Round(sy_monthlypayments * countYears * 12, 2);
sy_Interest = Math.Round(sy_Total - sy_Loan, 2);
//公积金贷款
gjj_monthlypayments = Math.Round((gjj_Loan * gjj_newlilv * Math.Pow(1 + gjj_newlilv, countYears * 12)) / (Math.Pow(1 + gjj_newlilv, countYears * 12) - 1), 2);
gjj_Total = Math.Round(gjj_monthlypayments * countYears * 12, 2);
gjj_Interest = Math.Round(gjj_Total - gjj_Loan, 2);
double monthlypayments = sy_monthlypayments + gjj_monthlypayments;
double Total = sy_Total + gjj_Total;
double Interest = sy_Interest + gjj_Interest;
double Loan=Math.Round( sy_Loan + gjj_Loan,2);
json.Append("{"purchase":"略","Loan":"" + Loan.ToString() + "","Forthemonth":"" + monthlypayments.ToString() + "","Total":"" + Total.ToString() + "","Interest":"" + Interest.ToString() + "","Shoufu":"0","months":"" + countYears * 12 + "(月)" + ""}");
break;
case "debj"://等额本金
string monthsPay = string.Empty;
double newmonthlypayments;;
double newTotal=0;
double newInterest;
double newLoan;
for (int i = 0; i < countYears * 12; i++)
{
sy_monthlypayments = sy_Loan / (countYears * 12) + (sy_Loan - sy_Loan / (countYears * 12) * i) * sy_newlilv;
gjj_monthlypayments =gjj_Loan / (countYears * 12) + (gjj_Loan - gjj_Loan / (countYears * 12) * i) * gjj_newlilv;
newmonthlypayments = sy_monthlypayments + gjj_monthlypayments;
monthsPay +="第"+ (i + 1) + "个月," + Math.Round(newmonthlypayments) + "(元)\r\n";//月均金额
sy_Total = sy_monthlypayments + sy_Total;
gjj_Total = gjj_monthlypayments + gjj_Total;
newTotal = gjj_Total + sy_Total;//还款总额
}
sy_Interest =sy_Total - sy_Loan;
gjj_Interest =gjj_Total - gjj_Loan;
newInterest = gjj_Interest + sy_Interest;
newLoan = sy_Loan + gjj_Loan;
json.Append("{"purchase":"略","Loan":"" + Math.Round(newLoan, 2) + "","Forthemonth":"" + monthsPay.ToString() + "","Total":"" + Math.Round(newTotal,2) + "","Interest":"" + Math.Round(newInterest, 2) + "","Shoufu":"0","months":"" + countYears * 12 + "(月)" + ""}");
break;
}
return json.ToString();
}
文章题目:c#实现房贷计算的方法源码-创新互联
网页URL:http://scyanting.com/article/dshdph.html
文章题目:c#实现房贷计算的方法源码-创新互联
网页URL:http://scyanting.com/article/dshdph.html