c#实现房贷计算的方法源码
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
string json=string.Empty;
string dktype = (!string.IsNullOrEmpty(context.Request.Form["dktype"]) ? context.Request.Form["dktype"].ToString().Trim() : "0");//贷款方式
string calculatype = (!string.IsNullOrEmpty(context.Request.Form["calculatype"]) ? context.Request.Form["calculatype"].ToString().Trim() : "0");//计算方式
string paymentType = (!string.IsNullOrEmpty(context.Request.Form["paymentType"]) ? context.Request.Form["paymentType"].ToString().Trim() : "0");//还款方式
string unitPrice = (!string.IsNullOrEmpty(context.Request.Form["unitPrice"]) ? context.Request.Form["unitPrice"].ToString().Trim() : "0");//单价
string acreage =(!string.IsNullOrEmpty(context.Request.Form["acreage"])?context.Request.Form["acreage"].ToString().Trim():"0");//面积
string mortgage = (!string.IsNullOrEmpty(context.Request.Form["mortgage"])?context.Request.Form["mortgage"].ToString().Trim():"0");//按揭成数
string loanceiling = (!string.IsNullOrEmpty(context.Request.Form["loanceiling"]) ? context.Request.Form["loanceiling"].ToString().Trim() : "0");//贷款总额
string countYears = (!string.IsNullOrEmpty(context.Request.Form["countYears"]) ? context.Request.Form["countYears"].ToString().Trim() : "0");//按揭年数
string lilv = (!string.IsNullOrEmpty(context.Request.Form["lilv"]) ? context.Request.Form["lilv"].ToString().Trim() : "0");//年利率 //组合型贷款
string syx_loanceiling = (!string.IsNullOrEmpty(context.Request.Form["syx_loanceiling"]) ? context.Request.Form["syx_loanceiling"].ToString().Trim() : "0");//商业贷款
string gjj_loanceiling = (!string.IsNullOrEmpty(context.Request.Form["gjj_loanceiling"]) ? context.Request.Form["gjj_loanceiling"].ToString().Trim() : "0");//公积金贷款
string sy_lilvValues = (!string.IsNullOrEmpty(context.Request.Form["sy_lilvValues"]) ? context.Request.Form["sy_lilvValues"].ToString().Trim() : "0");//商业贷款利率
string gjj_lilvValues = (!string.IsNullOrEmpty(context.Request.Form["gjj_lilvValues"]) ? context.Request.Form["gjj_lilvValues"].ToString().Trim() : "0");//公积金贷款利率
switch (dktype)
{
case "sydk"://商业贷款
case "gjjdk"://公积金贷款
switch (calculatype)
{
case "calcula_one"://根据面积,单价计算
json = returnResult(double.Parse(unitPrice), double.Parse(acreage), double.Parse(mortgage), Utils.ObjToInt(countYears, 1), double.Parse(lilv), paymentType);
break;
case "calcula_two"://根据贷款总额计算
json = returnResult(double.Parse(loanceiling), int.Parse(countYears), double.Parse(lilv), paymentType);
break;
}
break;
case "zhxdk"://组合型贷款
json = returnResult(double.Parse(syx_loanceiling), double.Parse(sy_lilvValues), double.Parse(gjj_loanceiling), double.Parse(gjj_lilvValues), Utils.ObjToInt(countYears,1), paymentType);
break;
}
context.Response.Write(json);
} /// <summary>
/// 商业贷款-根据面积,单价计算
/// </summary>
/// <param name="unitPrice">单价</param>
/// <param name="acreage">面积</param>
/// <param name="mortgage">按揭成数</param>
/// <param name="countYears">按揭年数</param>
/// <param name="lilv">年利率</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
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();
} /// <summary>
/// 商业贷款-根据贷款总额计算
/// </summary>
/// <param name="countYears">贷款总额</param>
/// <param name="countYears">按揭年数</param>
/// <param name="lilv">年利率</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
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();
} /// <summary>
/// 组合型贷款
/// </summary>
/// <param name="syx_loanceiling">商业贷款额</param>
/// <param name="sy_lilvValues">商业贷款利率(年利率)</param>
/// <param name="gjj_loanceiling">公积金贷款额</param>
/// <param name="gjj_lilvValues">公积金贷款额利率(年利率)</param>
/// <param name="countYears">贷款期限</param>
/// <param name="paymentType">还款方式</param>
/// <returns></returns>
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#实现房贷计算的方法源码的更多相关文章
- invalidate和requestLayout方法源码分析
invalidate方法源码分析 在之前分析View的绘制流程中,最后都有调用一个叫invalidate的方法,这个方法是啥玩意?我们来看一下View类中invalidate系列方法的源码(ViewG ...
- v8--sort 方法 源码 (1) 插入排序法
v8--sort方法源码中对于长度较短的数组使用的是插入排序法. 部分源码: function InsertionSort(a, from, to) { for (var i = from + 1; ...
- 从原子类和Unsafe来理解Java内存模型,AtomicInteger的incrementAndGet方法源码介绍,valueOffset偏移量的理解
众所周知,i++分为三步: 1. 读取i的值 2. 计算i+1 3. 将计算出i+1赋给i 可以使用锁来保持操作的原子性和变量可见性,用volatile保持值的可见性和操作顺序性: 从一个小例子引发的 ...
- HashMap实现原理一步一步分析(1-put方法源码整体过程)
各位同学大家好, 今天给大家分享一下HashMap内部的实现原理, 这一块也是在面试过程当中基础部分被问得比较多的一部分. 想要搞清楚HashMap内部的实现原理,我们需要先对一些基本的概念有一些了解 ...
- js-reduce方法源码
// 数组中的reduce方法源码复写 //先说明一下reduce原理:总的一句,reduce方法主要是把数组遍历, //然后把数组的每个元素传入回调函数中,回调函数怎么处理,就会的到什么样的效果 A ...
- Java split方法源码分析
Java split方法源码分析 public String[] split(CharSequence input [, int limit]) { int index = 0; // 指针 bool ...
- erlang下lists模块sort(排序)方法源码解析(二)
上接erlang下lists模块sort(排序)方法源码解析(一),到目前为止,list列表已经被分割成N个列表,而且每个列表的元素是有序的(从大到小) 下面我们重点来看看mergel和rmergel ...
- erlang下lists模块sort(排序)方法源码解析(一)
排序算法一直是各种语言最简单也是最复杂的算法,例如十大经典排序算法(动图演示)里面讲的那样 第一次看lists的sort方法的时候,蒙了,几百行的代码,我心想要这么复杂么(因为C语言的冒泡排序我记得不 ...
- getOrCreateEnvironment()方法源码探究
该方法目的是创建一个环境对象,并且根据环境类型,自动判断是创建web环境对象,还是标准非web环境对象. 首先该方法源于prepareEnvironment准备环境: 然后进入该方法源码: 可以发现: ...
随机推荐
- webView 点击页面跳转到浏览器
@interface ForumDetailViewController ()<UIWebViewDelegate> { NSUInteger _clickedNumber; } @end ...
- 解决“LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏”问题
更新VS2010,或者卸载VS2013安装2010后,建立项目时会出现"LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏"的错误 ...
- JQUERY 保存成功后又下角动态提示
$.messager.show({ // show error message title : '操作结果', msg : '操作成功!' });
- 关于JS获取来路url问题
Javascript 正常取来源网页的URL只要用: document.referrer 就可以了! 但,如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用: opene ...
- 【经验记录】Jconsole Jvisualvm 监控Tomcat
环境:centos 6 1.首先检查hostname是否正确,输入以下命令 hostname -i 如果输出机器ip,则表示正确,如果输出 hostname: Unknown host 查看/etc/ ...
- 关于oracle 10g creating datafile with zero offset for aix
参考文档: 1.创建oracle数据文件时需要注意的地方(OS Header Block) http://www.aixchina.net/Question/20406 2.oracle 创建数据文件 ...
- .net学习笔记--序列化与反序列化
序列化其实就是将一个对象的所有相关的数据保存为一个二进制文件(注意:是一个对象) 而且与这个对象相关的所有类型都必须是可序列化的所以要在相关类中加上 [Serializable]特性 对象类型包括:对 ...
- python模拟登陆知乎并爬取数据
一些废话 看了一眼上一篇日志的时间 已然是5个月前的事情了 不禁感叹光阴荏苒其实就是我懒 几周前心血来潮想到用爬虫爬些东西 于是先后先重写了以前写过的求绩点代码 爬了草榴贴图,妹子图网,后来想爬婚恋网 ...
- 使用AS编译jni文件无法编译出arm64-v8a,x86_64和mips64平台的.so文件的解决方法
我用的插件版本是:classpath 'com.android.tools.build:gradle-experimental:0.4.0',AS集成和使用ndk编译项目参考官方demo:https: ...
- Asp.Net MVC4入门指南(9):查询详细信息和删除记录
在本教程中,您将查看自动生成的Details和Delete方法. 查询详细信息和删除记录 打开Movie控制器并查看Details方法. public ActionResult Details(int ...