当前位置:首页 > Windows程序 > 正文

C#实现的等额本息法、按月付息到期还本法、一次性还本付息法

2021-03-24 Windows程序

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

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>投资金额</param>
        /// <param>年利率</param>
        /// <param>投资期限,单位:月</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;
        }
    }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/66804.html