博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#实现的等额本息法、按月付息到期还本法、一次性还本付息法
阅读量:5977 次
发布时间:2019-06-20

本文共 3926 字,大约阅读时间需要 13 分钟。

你若懂行,那便有用,如下:

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>
        /// 等额本息法
        /// </summary>
        /// <param name="amountT">投资金额</param>
        /// <param name="yearRate">年利率</param>
        /// <param name="monthsx">投资期限,单位:月</param>
        /// <returns></returns>
        public static List<BackUnit> Compute(double amount, double yearRate, int months)
        {

            var monthRate = (yearRate) / 1200.0;     //年利率转为月利率

            var datalist = new List<BackUnit>(); 
            var i = 0;
            var a = 0.0; // 偿还本息
            var b = 0.0; // 偿还利息
            var c = 0.0; // 偿还本金
            //利息收益
            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; // 剩余本金

            totalRateIncome = Math.Round(totalRateIncome * 100) / 100;// 支付总利息

            totalIncome = Math.Round(totalIncome * 100) / 100;
            a = totalIncome / months;    //每月还款本息
            a = Math.Round(a * 100) / 100;//每月还款本息

            for (i = 1; i <= months; i++)

            {
                b = (amount * monthRate * (Math.Pow((1 + monthRate), months) - Math.Pow((1 + monthRate), (i - 1)))) / (Math.Pow((1 + monthRate), 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;// 期数
                unit.TotalRate = totalRateIncome;// 总利息
                unit.TotalMoney = totalIncome;// 总还款
                unit.A = a;// 偿还本息  someNumber.ToString("N2");
                unit.B = b;// 偿还利息
                unit.C = c;// 偿还本金
                unit.D = d;// 剩余本金
                datalist.Add(unit);
            }

            return datalist;

        }
    }

    public class AnYueFuxiDaoqiHuanBen

    {
        /// <summary>
        /// 按月付息到期还本
        /// </summary>
        /// <param name="amount">投资金额</param>
        /// <param name="yearRate">年利率</param>
        /// <param name="months">投资期限,单位:月</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;// 期数
                unit.TotalRate = rateIncome;//Math.Round((Amount + TotalRate) * 100) / 100;// 总利息
                unit.TotalMoney = total;//TotalRate;// 总还款
                unit.A = rateIncomeEve;// 偿还本息  someNumber.ToString("N2");
                unit.B = rateIncomeEve;// 偿还利息
                unit.C = 0;// 偿还本金
                unit.D = amount * 1 + rateIncome * 1 - rateIncomeEve * i;// 剩余本金
                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>
        /// 一次性还本付息
        /// </summary>
        /// <param name="amount">投资金额</param>
        /// <param name="yearRate">年利率</param>
        /// <param name="months">投资期限,单位:月</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;// 期数

            unit.TotalRate = rateIncome;//Math.Round((Amount + TotalRate) * 100) / 100;// 总利息
            unit.TotalMoney = totalIncome;//TotalRate;// 总还款
            unit.A = totalIncome;// 偿还本息  someNumber.ToString("N2");
            unit.B = rateIncome;// 偿还利息
            unit.C = 0;// 偿还本金
            unit.D = 0;// 剩余本金
            return unit;
        }
    }

    public class BackUnit

    {
        //当前期数
        public int Number { get; set; }
        //总利息
        public double TotalRate { get; set; }
        //总还款
        public double TotalMoney { get; set; }
        //本期应还全部
        public double A { get; set; }
        //本期应还利息
        public double B { get; set; }
        //本期应还本金
        public double C { get; set; }
        //本期剩余本金
        public double D { get; set; }
    }

以下为运行结果:

再附送一个我所写的在线测试地址:。

转载地址:http://bfsox.baihongyu.com/

你可能感兴趣的文章
zencart中query_factory.php中连接mysql次数
查看>>
fail2ban 保护linux安全(转载)已用于生产环境
查看>>
表格元素的添加和删除,计算器,全选全不反选
查看>>
数据约束
查看>>
网络营销第七课(1):制定SEO计划(网站相关数据分析)
查看>>
nginx rewrite 参数和例子
查看>>
mysqldump命令
查看>>
github上传代码步骤
查看>>
利用express搭建一个restful api 服务器
查看>>
(转)调整.NET控件WebBrowser的默认浏览器内核版本
查看>>
[导入]让你的WAP网站有更好的兼容性
查看>>
.NET Exceptionless 本地部署踩坑记录
查看>>
TOMCAT 的 CONTEXT
查看>>
航电OJ-2544最短路
查看>>
CF772E Verifying Kingdom
查看>>
POJ 3417 Network
查看>>
雨林木风U盘装系统综合教程
查看>>
V-by-one
查看>>
让我欲罢不能的node.js
查看>>
python3基础知识学习记录
查看>>