package com.alex.examples.utils.money;import lombok.Data;import java.io.Serializable;
import java.math.BigDecimal;@Data
public class MoneyVo implements Serializable {private Integer number;//期数private BigDecimal monthPrincipalInterest;//本息private BigDecimal monthPrincipal;//本金private BigDecimal monthInterest;//利息}
package com.alex.examples.utils.money;import cn.hutool.core.math.MathUtil;import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;public class MoneyUtils {public static void main(String[] args) {Long principal = 1000000L; //贷款本息Double interest = 0.01; //月利息Integer months = 12; //贷款期数//        //等额本金
//        List<MoneyVo> list = DEBJ(new BigDecimal(MathUtil.centToYuan(principal)), interest, months);
//        list.forEach(vo -> System.out.println("期数:" + vo.getNumber()
//                + ",月供(元):" + vo.getMonthPrincipalInterest()
//                + ",本金(元):" + vo.getMonthPrincipal()
//                + ",利息(元):" + vo.getMonthInterest()));//        //等本等息
//        List<MoneyVo> list = DBDX(new BigDecimal(MathUtil.centToYuan(principal)), interest, months);
//        list.forEach(vo -> System.out.println("期数:" + vo.getNumber()
//                + ",月供(元):" + vo.getMonthPrincipalInterest()
//                + ",本金(元):" + vo.getMonthPrincipal()
//                + ",利息(元):" + vo.getMonthInterest()));//先息后本List<MoneyVo> list = XXHB(new BigDecimal(MathUtil.centToYuan(principal)), interest, months);list.forEach(vo -> System.out.println("期数:" + vo.getNumber()+ ",月供(元):" + vo.getMonthPrincipalInterest()+ ",本金(元):" + vo.getMonthPrincipal()+ ",利息(元):" + vo.getMonthInterest()));}/*** 等额本金* 定义:月还款总额逐月降低;月还款本金固定,为贷款总金额/期数;月还款利息逐渐降低,为每月剩余贷款余额*单期利息* 规则:例如【本金10000,月息1%,贷款12期】,则月还款本金=本金/期数;月利息:每期剩余本金*利息,* 如第一期应还利息=10000*1%=100;第二期应还利息=(10000-833.33)*1%=91.67......** @param principal:本金,单位分* @param interest:月利息,单位分* @param months:贷款期数,单位月* @return*/public static List<MoneyVo> DEBJ(BigDecimal principal, Double interest, Integer months) {List<MoneyVo> list = new ArrayList<>();BigDecimal money = principal; //剩余本金BigDecimal monthPrincipal = principal.divide(new BigDecimal(months), 2, BigDecimal.ROUND_HALF_UP); //月还款本金for (int i = 1; i < months + 1; i++) {MoneyVo vo = new MoneyVo();vo.setNumber(i);vo.setMonthPrincipal(monthPrincipal);//月应还利息if (i == 1) {BigDecimal monthInterest = principal.multiply(new BigDecimal(interest).setScale(2, BigDecimal.ROUND_HALF_UP));vo.setMonthInterest(monthInterest);money = principal.subtract(monthPrincipal).setScale(2, BigDecimal.ROUND_HALF_UP);} else {BigDecimal monthInterest = money.multiply(new BigDecimal(interest).setScale(2, BigDecimal.ROUND_HALF_UP)).setScale(2, BigDecimal.ROUND_HALF_UP);vo.setMonthInterest(monthInterest);money = money.subtract(monthPrincipal).setScale(2, BigDecimal.ROUND_HALF_UP);}//月应还本息BigDecimal monthPrincipalInterest = vo.getMonthPrincipal().add(vo.getMonthInterest()).setScale(2, BigDecimal.ROUND_HALF_UP);vo.setMonthPrincipalInterest(monthPrincipalInterest);//整合数据list.add(vo);}return list;}/*** 等本等息* 定义:月还款总额不变;月还款本金不变,为贷款总金额/期数;月还款利息不变,为贷款总金额*单期利率** @param principal:本金,单位分* @param interest:月利息,单位分* @param months:贷款期数,单位月* @return*/public static List<MoneyVo> DBDX(BigDecimal principal, Double interest, Integer months) {List<MoneyVo> list = new ArrayList<>();//月还款本金BigDecimal monthPrincipal = principal.divide(new BigDecimal(months), 2, BigDecimal.ROUND_HALF_UP);//月还款利息BigDecimal monthInterest = principal.multiply(new BigDecimal(interest)).setScale(2, BigDecimal.ROUND_HALF_UP);//月还款本息BigDecimal monthPrincipalInterest = monthPrincipal.add(monthInterest).setScale(2, BigDecimal.ROUND_HALF_UP);for (int i = 1; i < months + 1; i++) {MoneyVo vo = new MoneyVo();vo.setNumber(i);vo.setMonthPrincipal(monthPrincipal);vo.setMonthInterest(monthInterest);vo.setMonthPrincipalInterest(monthPrincipalInterest);list.add(vo);}return list;}/*** 先息后本* 定义:月还款总额不变,为月还款利息;月还款本金为0,在最后一期还总贷款额本金;月还款利息不变,为贷款总金额*单期利息** @param principal:本金,单位分* @param interest:月利息,单位分* @param months:贷款期数,单位月* @return*/public static List<MoneyVo> XXHB(BigDecimal principal, Double interest, Integer months) {List<MoneyVo> list = new ArrayList<>();//月还款本息=月还款利息BigDecimal monthPrincipalInterest = principal.multiply(new BigDecimal(interest)).setScale(2, BigDecimal.ROUND_HALF_UP);for (int i = 1; i < months + 1; i++) {MoneyVo vo = new MoneyVo();vo.setNumber(i);vo.setMonthInterest(monthPrincipalInterest);vo.setMonthPrincipalInterest(monthPrincipalInterest);if (i < months) {vo.setMonthPrincipal(new BigDecimal(0));} else {vo.setMonthPrincipal(principal);}list.add(vo);}return list;}
}
package com.alex.examples.utils.money;import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;/*** 等额本息计算工具类** <p>* 等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总额相加,* 然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。* <p>* 年利率=月利率×12(月)=日利率×360(天)* <p>* 月利率=年利率÷12(月)=日利率×30(天)* <p>* 日利率=年利率÷360(天)=月利率÷30(天)。*/
public class AverageCapitalPlusInterestUtils {/*** 每月偿还本金和利息* <p>* 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金,单位分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还本金和利息(入1 单位分)*/public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalMonth) {double monthRate = yearRate / 12;double perMonthPrincipalInterest = invest * (monthRate * Math.pow(1 + monthRate, totalMonth)) / (Math.pow(1 + monthRate, totalMonth) - 1);return new BigDecimal(perMonthPrincipalInterest).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();}/*** 等额本息的每月偿还利息* <p>* 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金,分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还利息(入1 单位分)*/public static Map<Integer, Double> getPerMonthInterest(double invest, double yearRate, int totalMonth) {Map<Integer, Double> map = new HashMap<>();double monthRate = yearRate / 12;double monthInterest;for (int i = 1; i < totalMonth + 1; i++) {double multiply = invest * monthRate;double sub = Math.pow(1 + monthRate, totalMonth) - Math.pow(1 + monthRate, i - 1);monthInterest = multiply * sub / (Math.pow(1 + monthRate, totalMonth) - 1);map.put(i, new BigDecimal(monthInterest).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());}return map;}/*** 等额本息的每月偿还本金(月还本息-月还利息)** @param invest     总借款额(贷款本金,分)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还本金(取整舍 单位分)*/public static Map<Integer, Double> getPerMonthPrincipal(double invest, double yearRate, int totalMonth) {double monthRate = yearRate / 12;double monthIncome = invest * monthRate * Math.pow(1 + monthRate, totalMonth)/ (Math.pow(1 + monthRate, totalMonth) - 1);double perMonthPrincipalInterest = new BigDecimal(monthIncome).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();Map<Integer, Double> mapPrincipal = new HashMap<>();double monthInterest;for (int i = 1; i < totalMonth + 1; i++) {Double multiply = invest * monthRate;double sub = (Math.pow(1 + monthRate, totalMonth)) - (Math.pow(1 + monthRate, i - 1));monthInterest = multiply * sub / (Math.pow(1 + monthRate, totalMonth) - 1);double monthInterestL = new BigDecimal(monthInterest).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();mapPrincipal.put(i, new BigDecimal(perMonthPrincipalInterest).subtract(new BigDecimal(monthInterestL)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());}return mapPrincipal;}/*** 等额本息的总利息** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 总利息 (单位分)*/public static double getInterestCount(double invest, double yearRate, int totalMonth) {double count = 0;Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, Double> entry : mapInterest.entrySet()) {count = new BigDecimal(count).add(new BigDecimal(entry.getValue())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();}return count;}public static void main(String[] args) {double invest = 10000; // 本金int month = 12;double yearRate = 0.01; // 年利率Double perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);System.out.println("等额本息---每月还款本息(每月还款本金+每月还款利息):" + perMonthPrincipalInterest);Map<Integer, Double> mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);System.out.println("等额本息---每月还款本金:" + mapPrincipal);Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, month);System.out.println("等额本息---每月还款利息:" + mapInterest);Double count = getInterestCount(invest, yearRate, month);System.out.println("等额本息---总利息:" + count);for (int i = 1; i < month + 1; i++) {if (i < month) {System.out.println("等额本息---" + i + "月还款本金:" + mapPrincipal.get(i) + ",还款利息:" + mapInterest.get(i));//剩余本金:总的本金-每月还款本金invest = new BigDecimal(invest).subtract(new BigDecimal(mapPrincipal.get(i))).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();} else {//最后一个月的还款利息=每月还款本息-剩余本金System.out.println("等额本息---" + i + "月还款本金:" + invest + ",还款利息:" + (new BigDecimal(perMonthPrincipalInterest).subtract(new BigDecimal(invest)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));}}}}

根据贷款还款方式(等额本金,等额本息,等本等息,先息后本),计算本息相关推荐

  1. 等额本金等额本息工具类2023

    等额本金&等额本息工具类2023 等额本金 等额本金 问题反馈 等额本金 import java.math.BigDecimal; import java.math.RoundingMode; ...

  2. 银行业务中贷款算法等额本金等额本息算法程序

    写一个贷款计算器,从网上找了一个算法,自己改了改可以用了,不错,分享给大家 import java.text.DecimalFormat; public class jshk { public sta ...

  3. 如何使用python进行等额本金-等额本息贷款计算

    #贷款额为a,月利率为i,年利率为I,还款月数为n a = 500000.00 I = 0.11495 i = I/12 n = 60 print("-----等额本息计算,以5个月为例-- ...

  4. java 等额本金等额本息工具类

    2019独角兽企业重金招聘Python工程师标准>>> 等额本息: /*** Description:等额本息工具类* Copyright: Copyright (corporati ...

  5. 等额本金.等额本息.房贷计算

    <?phpfunction debx(){$dkm = 12; //贷款月数,20年就是240个月$dkTotal = 2000; //贷款总额$dknl = 0.049; //贷款年利率$em ...

  6. 房贷利率有无套路?Python解读“等额本金与等额本息”的差异所在

    作者 | xiaoyu 来源 | Python数据科学 很多朋友留言说不知道房贷利率的不同归还方式是不是有套路,内心深表疑虑.我的第一反应是因为房贷很高,大家看到消费分期的套路自然而然就想到了房贷,很 ...

  7. python等额本息和等额本金_用Python解读房贷利率,要不要看随你

    可能很多买过房.贷过款的朋友大概都知道怎么回事,但是我相信大部分人也没细研究过,而绝大部分人买房时更是任由房屋中介摆布,因为给了中介费相信他们可以算的明明白白,自己也就不过多深究了.但我觉得买房不是小 ...

  8. Java计算等额本金和等额本息

    Java计算等额本金和等额本息 等额本金 等额本息 等额本金 /*** 等额本金是指一种贷款的还款方式,是在还款期内把贷款数总额等分,每月偿还同等数额的本金和剩余贷款在该月所产生的利息,这样由于每月的 ...

  9. 等额本息,等额本金区别

    等额本金,等额本息区别 买房银行贷款分为两种: 等额本金和等额本息 等额本息 等额本息定义:还款本金占比逐月递增,利息占比逐月递减,月还款数不变 由于每月的还款额度是一样的,其中每个月的还款包括了根据 ...

  10. QLExpress计算等本等息、等额本息、等额本金

    public class Interest { private ExpressRunner runner = new ExpressRunner(); public void initial() th ...

最新文章

  1. 安卓gridview 网格,多行多列实现
  2. 我和奇葩的故事之失联第七天
  3. IT小小鸟VS.小小小鸟:展翅,我们一起翱翔!
  4. CSS——如何清除浮动
  5. Oracle原理:11g的体系结构
  6. cp命令的编写——浅谈系统调用
  7. python跳出两层(多层)循环--使用标志量
  8. 剑指offer——面试题15:链表中倒数第k个结点
  9. MATLAB卷积运算(conv)
  10. 【Unity Shaders】ShadowGun系列之二——雾和体积光
  11. dCas9稳转细胞系概述
  12. 慕尼黑工业大学计算机博士申请条件,德国慕尼黑工业大学博士生申请条件
  13. android webview静态方法,在android webview中加载静态页面
  14. 什么是https证书?
  15. 百度UEditor编译器中获取HTML内容和纯文本,设置UEditor编辑器的内容
  16. 三级分销系统要如何进行推广以及提升曝光度?
  17. JAVA中native方法调用C语言实现学习
  18. Unity:DOTween来回运行或者缩放等LoopType.Yoyo
  19. 阿里云李津谈布局专有云的深层用意
  20. ios系统光遇是什么服务器,光遇国际服ios版

热门文章

  1. 微信小程序开发抽取HTML中数据的最快方法是正则表达式,而不是循环
  2. MEM/MBA英语基础(02) 句子成分基础
  3. QQ机器人{退出/回复设置/日志记录篇}
  4. java 实现限流器,可用于Rest接口请求处理 | Java工具类
  5. Vue学习笔记01-基础部分
  6. 零基础python爬虫基础之王者荣耀图片下载(超级简单)
  7. python 一个例子解释全局变量和局部变量
  8. 什么叫死区时间_死区时间
  9. 【software】常见流氓软件
  10. 用tensorboard可视化log日志