java 等额本金等额本息工具类
2019独角兽企业重金招聘Python工程师标准>>>
等额本息:
/*** Description:等额本息工具类* Copyright: Copyright (corporation)2015* Company: Corporation* @author: 凯文加内特* @version: 1.0* Created at: 2015年11月30日 下午3:45:46* Modification History:* Modified by : */package com.utils;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 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_DOWN);return monthIncome.doubleValue();}/*** 等额本息计算获取还款方式为等额本息的每月偿还利息* * 公式:每月偿还利息=贷款本金×月利率×〔(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), 6, 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 = 20000; // 本金int month = 12;double yearRate = 0.15; // 年利率double perMonthPrincipalInterest = getPerMonthPrincipalInterest(invest, yearRate, month);System.out.println("等额本息---每月还款本息:" + perMonthPrincipalInterest);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);}
}
等额本金:
/*** Description:等额本金工具类* Copyright: Copyright (Corporation)2015* Company: Corporation* @author: 凯文加内特* @version: 1.0* Created at: 2015年12月1日 上午8:38:23* Modification History:* Modified by : */package com.utils;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);}
}
转载于:https://my.oschina.net/ydsakyclguozi/blog/538210
java 等额本金等额本息工具类相关推荐
- 贷款计算器- 等额本金、等额本息工具类(Java版)
/** * Description:等额本金工具类 * Copyright: Copyright (Corporation)2015 * Company: Corporation * @version ...
- 等额本金、等额本息工具类(Java版)
等额本息: /** * Description:等额本息工具类 * Copyright: Copyright (corporation)2015 * Company: Corporation * @a ...
- 等额本金等额本息工具类2023
等额本金&等额本息工具类2023 等额本金 等额本金 问题反馈 等额本金 import java.math.BigDecimal; import java.math.RoundingMode; ...
- java 手机号脱敏,身份证号脱敏 工具类
java 手机号脱敏,身份证号脱敏 工具类 import org.apache.commons.lang3.StringUtils;/*** * @title: 脱敏工具类* @author: wll ...
- java将链接生成二维码工具类
一.添加依赖 <!-- 生成二维码--><dependency><groupId>com.google.zxing</groupId><artif ...
- Java - HuTool 使用 EscapeUtil、XmlUtil等工具类(四)
Java - HuTool 使用 EscapeUtil.XmlUtil等工具类(四) 本篇主要介绍 HuTool工具, 其是 java工具类,对于一些静态方法进行封装,虽然很小,但很全,里面拥有平时我 ...
- Java生成和解析二维码工具类(简单经典)
Java生成和解析二维码工具类 开箱即用,简单不废话. pom.xml引入依赖 <!-- https://mvnrepository.com/artifact/com.google.zxing/ ...
- 记录一下:Java 汉字获取拼音或首字母工具类
记录一下:Java 汉字获取拼音或首字母工具类 Maven依赖配置 Java代码 本文主要记录一下在Java中,如何将字符串中的中文转化为拼音,获取汉字串拼音首字母,获取汉字串拼音的工具类,以及相关的 ...
- Java教程:微信排序并加密工具类
Java教程:微信排序并加密工具类 源码: import cn.bsit.commons.md5.MD5Utils;import java.util.Arrays; import java.util. ...
最新文章
- 关于最长公共子序列的执行过程
- C语言 —— 运算符的优先级
- Python中常见的数据类型小结
- Adobe 2022软件安装错误代码107解决办法
- python查看图像通道数(通过PIL)
- python yield
- 无声也能语音识别?微软这个黑科技有点厉害
- 【C/C++】C/C++中Static的作用详述
- HDU 1016 DFS
- 函数的基本知识点总结(附实例)
- 写一个含数字,拼音,汉字的验证码生成类
- 基于大数据技术的电信客户流失预测模型 研究及应用 大数据
- 阿里图标库运用于项目---实例
- 【愚公系列】2022年01月 Django商城项目18-用户中心-密码修改功能页面设计
- OSChina 周三乱弹 —— 风扇写着先生请自爱
- 【STM32】时钟相关函数和类型
- 夜深了,最好喝点咖啡
- Learn Git Branching 笔记
- Lenovo Y430P安装Linux无线网卡
- 嵌入式开发使用虚拟机的基本服务安装
热门文章
- LineatLayout设置背景为.9图后产生位移
- 【Gradle】借助gradle的ProductFlavor实现多App间代码库复用
- java Cast Exception
- select子查询多个字段_SQL复杂查询
- IoC容器和Dependency Injection模式
- tornado 学习笔记15 _ServerRequestAdapter分析
- 这样就算会了PHP么?-9
- Flash XSS 漏洞详解 根治的好办法
- 网站开发常用jQuery插件总结(四)验证插件validation
- redhat及deban系列linux软件管理的一些问题