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准备环境: 然后进入该方法源码: 可以发现: ...
随机推荐
- oracle分组后取每组第一条数据
数据格式: 分组取第一条的效果: sql语句: SELECT * FROM ( ;
- R语言画图,根据正负值画不同颜色,并且画水平线或者垂直线
col=ifelse(x<0, "blue", "red") #如果x值为负值,用蓝色表示,反之,用红色表示 abline(v=0,col="g ...
- libcurl 函数curl_easy_perform在release下崩溃的问题
今天遇到一个很奇怪的问题: 工程中用到了libcurl, debug可以正常运行,release每次都崩溃,断到curl_easy_perform这一行.堆栈中也得不到有用信息,于是GOOGLE一番, ...
- HTML5离线篇收藏--- cache manifest
自从翻译了<解读 HTML5:建议.技巧和技术>,就一直没有时间去看 HTML5 相关的东西.上周一次偶然的工作间隙折腾了下 Cache Manifest .当时直接拿博客当测试环境,虽然 ...
- poj1087 A Plug for UNIX(网络流最大流)
http://poj.org/problem?id=1087 好久没遇见过这么坑的题了这个题真是挫的够可以的.题目大意:你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器 ...
- Java(类与对象)
1>对象判等 请输入并运行以下代码,得到什么结果? public class Test { public static void main(String[] args) { // TODO Au ...
- three.js 根据png生成heightmap
Three.js: render real world terrain from heightmap using open data By jos.dirksen on Tue, 07/17/2012 ...
- 在CMMI推广过程中EPG常犯的错误(转)
本文转自: http://developer.51cto.com/art/200807/86953.htm 仅用于个人收藏,学习.如有转载,请联系原作者. ---------------------- ...
- java socket 网络编程常见异常
1.java.net.SocketTimeoutException 这个异常比较常见,socket超时.一般有2个地方会抛出这个,一个是connect的时候,这个超时参数由connect(Socket ...
- jsp文件引入js文件的方式(项目部署于web容器中)
在页面中引入javascript文件的方式是多种多样的,本文介绍两种. 通过<script>标签插入js文件 通过这种方式引入的js,写对js文件和jsp文件的路径很重要.下面给出一个项目 ...