等额本金&等额本息工具类2023

  • 等额本金
  • 等额本金
  • 问题反馈

等额本金

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;/*** 等额本金工具类* <p>* 等额本金是指一种贷款的还款方式,是在还款期内把贷款数总额等分,每月偿还同等数额的本金和剩余贷款在该月所产生的利息,这样由于每月的还款本金额固定,* 而利息越来越少,借款人起初还款压力较大,但是随时间的推移每月还款数也越来越少。** @author xl.niu* @since 2023/6/5*/
public class AverageCapitalUtils {/*** 等额本金的每月偿还本金和利息* <p>* 公式:每月偿还本金=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还本金和利息, 不四舍五入,直接截取小数点最后两位*/public static Map<Integer, BigDecimal> getPerMonthPrincipalInterest(double invest, double yearRate, int totalMonth) {Map<Integer, BigDecimal> map = new HashMap<Integer, BigDecimal>();// 每月本金BigDecimal monthPri = getPerMonthPrincipal(invest, totalMonth);// 每月利息Map<Integer, BigDecimal> monthInterests = getPerMonthInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, BigDecimal> entry : monthInterests.entrySet()) {map.put(entry.getKey(), entry.getValue().add(monthPri).setScale(2, RoundingMode.CEILING));}return map;}/*** 等额本金的每月偿还利息* <p>* 公式:每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 每月偿还利息*/public static Map<Integer, BigDecimal> getPerMonthInterest(double invest, double yearRate, int totalMonth) {Map<Integer, BigDecimal> inMap = new HashMap<Integer, BigDecimal>();BigDecimal monthPrincipal = getPerMonthPrincipal(invest, totalMonth);//月偿还本金double monthRate = yearRate / 12;BigDecimal monthRateBigDecimal = new BigDecimal(String.valueOf(monthRate));//月利率for (int i = 1; i <= totalMonth; i++) {BigDecimal investBigDecimal = new BigDecimal(String.valueOf(invest));//本金BigDecimal finishPrincipal = monthPrincipal.multiply(new BigDecimal((i - 1)));//已还本金合计BigDecimal unfinish = investBigDecimal.subtract(finishPrincipal);BigDecimal monthInterest = unfinish.multiply(monthRateBigDecimal);inMap.put(i, monthInterest);}return inMap;}/*** 等额本金的每月偿还本金* <p>* 公式:每月应还本金=贷款本金÷还款月数** @param invest     总借款额(贷款本金)* @param totalMonth 还款总月数* @return 每月偿还本金*/public static BigDecimal getPerMonthPrincipal(double invest, int totalMonth) {return new BigDecimal(invest).divide(new BigDecimal(totalMonth), 4, BigDecimal.ROUND_DOWN);}/*** 等额本金的总利息** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalMonth 还款总月数* @return 总利息*/public static BigDecimal getInterestCount(double invest, double yearRate, int totalMonth) {BigDecimal count = new BigDecimal(0);Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {count = count.add(entry.getValue());}return count;}/*** @param args*/public static void main(String[] args) {double invest = 20000; // 本金double yearRate = 0.15; // 年利率int month = 12;BigDecimal principal = getPerMonthPrincipal(invest, month);//月偿还本金Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, month);//月偿还利息Map<Integer, BigDecimal> getPerMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);//月还款合计System.out.println("序号\t利息\t\t本金\t\t每月还款本息");for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {System.out.println(entry.getKey() + "\t" + entry.getValue().setScale(2, BigDecimal.ROUND_HALF_UP) + "\t" + principal.setScale(2, RoundingMode.CEILING) + "\t" + getPerMonthPrincipalInterest.get(entry.getKey()));}BigDecimal count = getInterestCount(invest, yearRate, month);System.out.println("等额本金---总利息:" + count.setScale(2, BigDecimal.ROUND_HALF_UP));}
}

等额本金


import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;/*** 等额本息工具类* <p>* 等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总额相加,* 然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。** @author xl.niu* @since 2023/6/5*/
public class AverageCapitalPlusInterestUtils {/*** 等额本息的每月偿还本金和利息* 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalmonth 还款总月数* @return 每月偿还本金和利息, 四舍五入*/public static double getPerMonthPrincipalInterest(double invest, double yearRate, int totalmonth) {double monthRate = yearRate / 12;BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth))).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_HALF_UP);return monthIncome.doubleValue();}/*** 等额本息的每月偿还利息* <p>* 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalmonth 还款总月数* @return 每月偿还利息*/public static Map<Integer, BigDecimal> getPerMonthInterest(double invest, double yearRate, int totalmonth) {Map<Integer, BigDecimal> map = new HashMap<Integer, BigDecimal>();double monthRate = yearRate / 12;BigDecimal monthInterest;for (int i = 1; i < totalmonth + 1; i++) {BigDecimal multiply = new BigDecimal(invest).multiply(new BigDecimal(monthRate));BigDecimal sub = new BigDecimal(Math.pow(1 + monthRate, totalmonth)).subtract(new BigDecimal(Math.pow(1 + monthRate, i - 1)));monthInterest = multiply.multiply(sub).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 6, BigDecimal.ROUND_HALF_UP);monthInterest = monthInterest.setScale(2, BigDecimal.ROUND_HALF_UP);map.put(i, monthInterest);}return map;}/*** 等额本息的每月偿还本金** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalmonth 还款总月数* @return 每月偿还本金*/public static Map<Integer, BigDecimal> getPerMonthPrincipal(double invest, double yearRate, int totalmonth) {double monthRate = yearRate / 12;BigDecimal monthIncome = new BigDecimal(invest).multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth))).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_HALF_UP);Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);Map<Integer, BigDecimal> mapPrincipal = new HashMap<Integer, BigDecimal>();for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {mapPrincipal.put(entry.getKey(), monthIncome.subtract(entry.getValue()));}return mapPrincipal;}/*** 等额本息的总利息** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalmonth 还款总月数* @return 总利息*/public static double getInterestCount(double invest, double yearRate, int totalmonth) {BigDecimal count = new BigDecimal(0);Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, totalmonth);for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {count = count.add(entry.getValue());}return count.doubleValue();}/*** 应还总和** @param invest     总借款额(贷款本金)* @param yearRate   年利率* @param totalmonth 还款总月数* @return 应还本金总和*/public static double getPrincipalInterestCount(double invest, double yearRate, int totalmonth) {double monthRate = yearRate / 12;BigDecimal perMonthInterest = new BigDecimal(invest).multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, totalmonth))).divide(new BigDecimal(Math.pow(1 + monthRate, totalmonth) - 1), 2, BigDecimal.ROUND_HALF_UP);BigDecimal count = perMonthInterest.multiply(new BigDecimal(totalmonth));count = count.setScale(2, BigDecimal.ROUND_HALF_UP);return count.doubleValue();}/*** @param args*/public static void main(String[] args) {double invest = 20000; // 本金double yearRate = 0.15; // 年利率int month = 12;double perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);//每月还款本息Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, month);//每月还款利息Map<Integer, BigDecimal> mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);//每月还款本金System.out.println("序号\t利息\t\t本金\t\t每月还款本息");for (Map.Entry<Integer, BigDecimal> entry : mapInterest.entrySet()) {System.out.println(entry.getKey() + "\t" + entry.getValue() + "\t" + mapPrincipal.get(entry.getKey()) + "\t" + perMonthPrincipalInterest);}double count = getInterestCount(invest, yearRate, month);System.out.println("等额本息---总利息:" + count);double principalInterestCount = getPrincipalInterestCount(invest, yearRate, month);System.out.println("等额本息---应还本息总和:" + principalInterestCount);}
}

问题反馈

等额本金等额本息工具类2023相关推荐

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

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

  2. 贷款计算器- 等额本金、等额本息工具类(Java版)

    /** * Description:等额本金工具类 * Copyright: Copyright (Corporation)2015 * Company: Corporation * @version ...

  3. 等额本金、等额本息工具类(Java版)

    等额本息: /** * Description:等额本息工具类 * Copyright: Copyright (corporation)2015 * Company: Corporation * @a ...

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

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

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

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

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

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

  7. Java之~ 等额本息,等额本金,组合贷

    一,等额本息工具类 import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.HashMap; imp ...

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

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

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

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

最新文章

  1. mysql主键始终从小到大_Mysql从入门到入神之(四)B+树索引
  2. 168. Leetcode 134. 加油站 (贪心算法-模拟题目)
  3. wince怎么刷carplay_Carplay支持仪表/HUD显示 宝马为全球超750000辆车发布OTA升级
  4. 安装openstack_午餐前如何安装OpenStack Cloud
  5. Leetcode:5.longest-palindromic-substring(最长回文子串)
  6. [Delphi]怎样访问Internet Explorer中的WebBrowser
  7. C++“”字符与字符“”相加是连接
  8. 215.数组中第的K个最大元素(力扣leetcode) 博主可答疑该问题
  9. 【Spring-tx】事务逻辑
  10. php排序商品价格的功能,织梦做商城,按销量,价格等自定义模型字段排序列表解决方案...
  11. python中re模块的span_python3正则模块re的使用方法详解
  12. 【2019.05】腾讯防水墙滑动验证码破解 python + selenium + OpenCV
  13. 怎样把PDF转换成PPT?迅捷PDF转换器来助力
  14. 不错的U3D第一人称射击类游戏教程
  15. LocalSend 电脑和手机互传软件教程解答手机端无法搜索到电脑的解决方案
  16. 抖音电商难做吗?为什么又累又卷还是做不好?
  17. 【经典算法】·二分法
  18. 安装torch_points3d时提示 No such file or directory: nvcc
  19. 5G主要技术场景与六大关键技术
  20. 设计模式(一)继承+组合

热门文章

  1. Rosetta 蛋白抗体设计有困难?小白速看
  2. Easyx图形库+C++做一个贪吃蛇小游戏 数据结构课程设计
  3. html 绘制 拓扑图,如何绘制网页版拓扑图
  4. 关于矩阵之行列式、方阵、逆矩阵的理解
  5. tcp/ip协议详解——HTTP协议和POP3协议SSL加密协议
  6. Dbvis连接Mysql驱动问题
  7. 【Helm三部曲】 Helm 包管理器 chartmuseum 简介及安装
  8. you-get教程(基础+进阶)
  9. TS5A3167DCKR
  10. 【NOIP2017普及组正式赛】 图书管理员