//*********************等额本息测试通过,等额本金暂未测试***************************package com.hez.platform.hez.housing.lendersToolBox.controller;import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/**** @author ldb* @date 2020-10-09*/@Api(tags = "房贷计算器")
@RestController
@RequestMapping("/lendersToolBox")
public class LendersToolBoxController {public static void main(String[] args) {//temp[][0]为每月还款本金 temp[][1]为每月还款利息 temp[][2]为每月还款总额double[][] detail = aaaaa();System.out.println(detail[0][0]);System.out.println(detail[0][1]);System.out.println(detail[0][2]);for(int i = 0;i<detail.length;i++){System.out.println("本金="+detail[i][0]+";利息="+detail[i][1]+";总额"+detail[i][2]);}}/*** 等额本息* @author ldb* @date 2020-09-29*/@PostMapping("/aaaaa")@RequiresPermissions("lendersToolBox:aaaaa")@ApiOperation(httpMethod = "POST", value = "等额本息")public static double[][] aaaaa() {double loanMoney = 740000; //贷款金额int years = 30; //贷款年限double yIns = 5.88; //年利率double totalMoney; //还款金额(本金+利息)double totalInterests; //利息总额double detail[][]; //每月还款详情double mIns = yIns / 100 / 12; //月利率int months = (years * 12); //还款所需月份double pow = Math.pow(1 + mIns,months);double remains = loanMoney;totalMoney = (months * loanMoney * mIns * pow) / (pow - 1); //总还款金额totalMoney = Math.floor(totalMoney * 100 + 0.5) / 100; //floor函数 保留两位小数totalInterests = totalMoney - loanMoney;totalInterests = Math.floor(totalInterests * 100 + 0.5) / 100;double temp[][] = new double[months][3];for (int i = 0; i < months; i++) {if(i == months - 1) {temp[i][1] = remains * mIns;temp[i][1] = Math.floor(temp[i][1] * 100 + 0.5) / 100;temp[i][0] = remains;temp[i][0] = Math.floor(temp[i][0] * 100 + 0.5) / 100;temp[i][2] = temp[i][0] + temp[i][1];temp[i][2] = Math.floor(temp[i][2] * 100 + 0.5) / 100;break;}//由于精度问题 最后一个月实际的本金会有差别 需要单独计算temp[i][1] = remains * mIns;temp[i][1] = Math.floor(temp[i][1] * 100 + 0.5) / 100;temp[i][2] = totalMoney / months;temp[i][2] = Math.floor(temp[i][2] * 100 + 0.5) / 100;temp[i][0] = temp[i][2] - temp[i][1];temp[i][0] = Math.floor(temp[i][0] * 100 + 0.5) / 100;remains -= temp[i][0];}//temp[][0]为每月还款本金 temp[][1]为每月还款利息 temp[][2]为每月还款总额detail = temp;return detail;}//等额本金public void bbbbb() {// double mIns = yIns / 100 / 12; //月利率
// int months = (years * 12);
// double remains = loanMoney;
// double sum = 0; // 总计还款金额
// double temp[][] = new double[months][3];
// for (int i = 0; i < months; i++)
// {
// temp[i][0] = loanMoney / months;
// temp[i][0] = Math.floor(temp[i][0] * 100 + 0.5) / 100;
// temp[i][1] = remains * mIns;
// temp[i][1] = Math.floor(temp[i][1] * 100 + 0.5) / 100;
// remains -= temp[i][0];
// temp[i][2] = temp[i][0] + temp[i][1];
// temp[i][2] = Math.floor(temp[i][2] * 100 + 0.5) / 100;
// sum += temp[i][2];
// }
// //temp[][0]为每月还款本金 temp[][1]为每月还款利息 temp[][2]为每月还款总额
// detail = temp;
// totalMoney = sum;
// totalMoney = Math.floor(totalMoney * 100 + 0.5) / 100;
// totalInterests = totalMoney - loanMoney;
// totalInterests = Math.floor(totalInterests * 100 + 0.5) / 100;}}
//转载自哪个忘了.找不到了.