/**  * Description:等额本金工具类  * Copyright: Copyright (Corporation)2015  * Company: Corporation  * @version: 1.0  * Modification History:  * Modified by :   */
package com.base.framework.core.util;import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;/*** 等额本金是指一种贷款的还款方式,是在还款期内把贷款数总额等分,每月偿还同等数额的本金和剩余贷款在该月所产生的利息,这样由于每月的还款本金额固定,* 而利息越来越少,借款人起初还款压力较大,但是随时间的推移每月还款数也越来越少。*/
public class AverageCapitalUtils {/*** 等额本金计算获取还款方式为等额本金的每月偿还本金和利息* * 公式:每月偿还本金=(贷款本金÷还款月数)+(贷款本金-已归还本金累计额)×月利率* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @return 每月偿还本金和利息,不四舍五入,直接截取小数点最后两位*/public static Map<Integer, Double> getPerMonthPrincipalInterest(double invest, double yearRate, int totalMonth) {Map<Integer, Double> map = new HashMap<Integer, Double>();// 每月本金double monthPri = getPerMonthPrincipal(invest, totalMonth);// 获取月利率double monthRate = yearRate / 12;monthRate = new BigDecimal(monthRate).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();for (int i = 1; i <= totalMonth; i++) {double monthRes = monthPri + (invest - monthPri * (i - 1)) * monthRate;monthRes = new BigDecimal(monthRes).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();map.put(i, monthRes);}return map;}/*** 等额本金计算获取还款方式为等额本金的每月偿还利息* * 公式:每月应还利息=剩余本金×月利率=(贷款本金-已归还本金累计额)×月利率* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @return 每月偿还利息*/public static Map<Integer, Double> getPerMonthInterest(double invest, double yearRate, int totalMonth) {Map<Integer, Double> inMap = new HashMap<Integer, Double>();double principal = getPerMonthPrincipal(invest, totalMonth);Map<Integer, Double> map = getPerMonthPrincipalInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, Double> entry : map.entrySet()) {BigDecimal principalBigDecimal = new BigDecimal(principal);BigDecimal principalInterestBigDecimal = new BigDecimal(entry.getValue());BigDecimal interestBigDecimal = principalInterestBigDecimal.subtract(principalBigDecimal);interestBigDecimal = interestBigDecimal.setScale(2, BigDecimal.ROUND_DOWN);inMap.put(entry.getKey(), interestBigDecimal.doubleValue());}return inMap;}/*** 等额本金计算获取还款方式为等额本金的每月偿还本金* * 公式:每月应还本金=贷款本金÷还款月数* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @return 每月偿还本金*/public static double getPerMonthPrincipal(double invest, int totalMonth) {BigDecimal monthIncome = new BigDecimal(invest).divide(new BigDecimal(totalMonth), 2, BigDecimal.ROUND_DOWN);return monthIncome.doubleValue();}/*** 等额本金计算获取还款方式为等额本金的总利息* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @return 总利息*/public static double getInterestCount(double invest, double yearRate, int totalMonth) {BigDecimal count = new BigDecimal(0);Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, totalMonth);for (Map.Entry<Integer, Double> entry : mapInterest.entrySet()) {count = count.add(new BigDecimal(entry.getValue()));}return count.doubleValue();}/*** @param args*/public static void main(String[] args) {double invest = 10000; // 本金int month = 12;double yearRate = 0.15; // 年利率Map<Integer, Double> getPerMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);System.out.println("等额本金---每月本息:" + getPerMonthPrincipalInterest);double benjin = getPerMonthPrincipal(invest, month);System.out.println("等额本金---每月本金:" + benjin);Map<Integer, Double> mapInterest = getPerMonthInterest(invest, yearRate, month);System.out.println("等额本金---每月利息:" + mapInterest);double count = getInterestCount(invest, yearRate, month);System.out.println("等额本金---总利息:" + count);}
}
/**  * Description:等额本息工具类  * Copyright: Copyright (corporation)2015  * Company: Corporation  * @version: 1.0  * Modification History:  * Modified by :   */
package com.base.framework.core.util;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;/*** 等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总额相加,* 然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。*/public class AverageCapitalPlusInterestUtils {/*** 等额本息计算获取还款方式为等额本息的每月偿还本金和利息* * 公式:每月偿还本息=〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @return 每月偿还本金和利息,不四舍五入,直接截取小数点最后两位*/public static BigDecimal 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_UP);//return monthIncome.doubleValue();return monthIncome;}/*** 等额本息计算获取还款方式为等额本息的每月偿还利息* * 公式:每月偿还利息=贷款本金×月利率×〔(1+月利率)^还款月数-(1+月利率)^(还款月序号-1)〕÷〔(1+月利率)^还款月数-1〕* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @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), 2,BigDecimal.ROUND_DOWN);monthInterest = monthInterest.setScale(2, BigDecimal.ROUND_DOWN);map.put(i, monthInterest);}return map;}/*** 等额本息计算获取还款方式为等额本息的每月偿还本金* * @param invest*            总借款额(贷款本金)* @param yearRate*            年利率* @param month*            还款总月数* @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_DOWN);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 month*            还款总月数* @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 month*            还款总月数* @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_DOWN);BigDecimal count = perMonthInterest.multiply(new BigDecimal(totalmonth));count = count.setScale(2, BigDecimal.ROUND_DOWN);return count.doubleValue();}/*** @param args*/public static void main(String[] args) {double invest = 38988; // 本金int month = 12;double yearRate = 0.15; // 年利率BigDecimal perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);System.out.println("等额本息---每月还款本息:" + perMonthPrincipalInterest);System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 3));System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 6));System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 9));System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 12));System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 15));System.out.println("等额本息---每月还款本息:" + getPerMonthPrincipalInterest(invest, yearRate, 18));/*Map<Integer, BigDecimal> mapInterest = getPerMonthInterest(invest, yearRate, month);System.out.println("等额本息---每月还款利息:" + mapInterest);Map<Integer, BigDecimal> mapPrincipal = getPerMonthPrincipal(invest, yearRate, month);System.out.println("等额本息---每月还款本金:" + mapPrincipal);double count = getInterestCount(invest, yearRate, month);System.out.println("等额本息---总利息:" + count);double principalInterestCount = getPrincipalInterestCount(invest, yearRate, month);System.out.println("等额本息---应还本息总和:" + principalInterestCount);*/}
}

贷款计算器- 等额本金、等额本息工具类(Java版)相关推荐

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

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

  2. 腾讯开放平台接口鉴权(计算签名)工具类 java版

    腾讯开放平台 接口鉴权(签名)工具类 java版 用到了Hutool工具类 package top.seasmall.platform.core.config.nettyws.util;import ...

  3. 方差计算工具类--Java版

    方差的计算,如果不太计较精度的话,可以使用 Apache 的 commons-math3(http://commons.apache.org/proper/commons-math/)提供的 Vari ...

  4. 坐标系转换工具类Java版Js版

    Java版本: public class GPSUtils {private static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;// ...

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

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

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

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

  7. SHA1签名工具类java

    SHA1签名工具类java package com.net.util;import java.security.MessageDigest; import java.util.Iterator; im ...

  8. 自定义日期工具类 java 1614698552

    自定义日期工具类 java 1614698552 需求 思路 演练 日期转字符串的方法 字符串转日期方法 测试类 更多尝试 测试另一个方法

  9. 财务转换工具 - 人民币金额转大写工具类 java 版本

    文章目录 财务转换工具 - 人民币金额转大写工具类 java 版本 1.示例 2.代码 财务转换工具 - 人民币金额转大写工具类 java 版本 1.示例 public static void mai ...

最新文章

  1. mysql8.0.12插件_mysql 8.0.12 安装使用教程
  2. IOS6学习笔记(四)
  3. Linux易混名词整理和相关操作
  4. 图像增强——基于OpenCV的图像色彩增强
  5. cogs 1656. 膜拜神犇
  6. C++原子操作 atomic的使用及效率
  7. 整数输入有理循环小数 1/7 = 0.142857142... 是个无限循环小数。 任何有理数都可以表示为无限循环小数的形式。 本题目要求即是:给出一个数字的循环小数表示法。...
  8. linux下的磁盘配额简介暨 linux下加挂硬盘续
  9. python学习笔记2---内置函数
  10. fcntl函数详解-文件锁
  11. svn命令行回滚到指定版本
  12. 《华为基本法》-笔记
  13. super oj p528
  14. 从一路赞美到嘘声不断 90后创业热潮已宣告死亡
  15. 详解区块链项目如何做主体搭建?
  16. easypoi 语法_高中语法精讲系列七丨高中英语八大语法之“名词性从句”要点归纳...
  17. Program Files可以删除吗?绝对不可以!
  18. 如何将格式工厂添加到右键
  19. 计算机网络网卡是什么东西,网卡坏了有什么现象?判断电脑网卡坏的方法
  20. django 加 celery 异步任务配置到成功运行

热门文章

  1. 手机屏幕常见故障_手机测试常见问题总结!
  2. 关于前端页面展示图片展示时改变方向的解决办法
  3. 通过windows自带远程桌面,实现不同局域网的电脑相互访问(默默P2P远程桌面管理工具-直接内网穿透)
  4. alert angularjs
  5. Java画图板界面上的添加
  6. 阿里云 ACP 认证,分享下经验心得
  7. PS将图片的背景填充变为无色
  8. 毕业论文Word格式订正技巧
  9. JAVA要不要看源码_为什么要看源码、如何看源码,高手进阶必看
  10. 如何利用手机云控系统来体现