成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

java中每月等額與先息后本計算

一般信用貸款會提供兩種還款方式:每月等額或者先息后本。每月等額,就是每月歸還等同的部分本金和利息,你手里在使用的本金其實是逐月減少的。先息后本就是先還利息,到期歸還本金。

十年的杭錦后網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整杭錦后建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)公司從事“杭錦后網(wǎng)站設(shè)計”,“杭錦后網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

每月等額

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
/**
 * <p>Title: 等額本息還款工具類</p>
 *
 */
public class CPMUtils{
 /**
 * <p>Description: 每月還款總額?!操J款本金×月利率×(1+月利率)^還款月數(shù)〕÷〔(1+月利率)^還款月數(shù)-1〕</p>
 * @param principal 貸款本金
 * @param monthlyInterestRate 月利率
 * @param amount 期數(shù)
 * @return
 */
 public static BigDecimal monthlyRepayment(BigDecimal principal, BigDecimal monthlyInterestRate, int amount){
 //(1+月利率)^還款月數(shù)
 BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(amount);
 return principal.multiply(monthlyInterestRate)
   .multiply(temp)
   .divide(temp.subtract(MoneyUtils.ONE), MoneyUtils.MATHCONTEXT);
 }
 /**
 * <p>Description: 月還款利息。(貸款本金×月利率-月還款額)*(1+月利率)^(當(dāng)前期數(shù)-1)+月還款額</p>
 * @param principal 貸款本金
 * @param monthlyInterestRate 月利率
 * @param monthlyRepayment 月還款額
 * @param number 當(dāng)前期數(shù)
 * @return
 */
 public static BigDecimal monthlyInterest(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal monthlyRepayment, int number){
 //(1+月利率)^(當(dāng)前期數(shù)-1)
 BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(number - 1);
 return principal.multiply(monthlyInterestRate)
   .subtract(monthlyRepayment)
   .multiply(temp).add(monthlyRepayment, MoneyUtils.MATHCONTEXT);
 }
 /**
 * <p>Description: 還款總利息。期數(shù)×貸款本金×月利率×(1+月利率)^期數(shù)÷〔(1+月利率)^期數(shù)-1〕-貸款本金 </p>
 * @param principal 貸款本金
 * @param monthlyInterestRate 月利率
 * @param amount 還款期數(shù)
 * @return
 */
 public static BigDecimal interest(BigDecimal principal, BigDecimal monthlyInterestRate, int amount){
 //(1+月利率)^期數(shù)
 BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(amount);
 return new BigDecimal(amount)
   .multiply(principal)
   .multiply(monthlyInterestRate)
   .multiply(temp)
   .divide(temp.subtract(MoneyUtils.ONE), MoneyUtils.MATHCONTEXT)
   .subtract(principal, MoneyUtils.MATHCONTEXT);
 }
 /**
 * <p>Description: 月還款本金。已經(jīng)精確到分位,未做單位換算</p>
 * @param principal 貸款本金
 * @param monthlyInterestRate 月利率
 * @param monthlyRepayment 月還款額
 * @param number 當(dāng)前期數(shù)
 * @return
 */
 public static BigDecimal monthlyPrincipal(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal monthlyRepayment, int number){
 BigDecimal monthInterest = monthlyInterest(principal, monthlyInterestRate, monthlyRepayment, number);
 //月還款額-月還款利息
 return monthlyRepayment.subtract(monthInterest).setScale(MoneyUtils.MONEYSHOWSCALE, MoneyUtils.SAVEROUNDINGMODE);
 }
 /**
 * <p>Description: 月還款本金。已經(jīng)精確到分位,未做單位換算</p>
 * @param monthRepayment 月還款總額
 * @param monthInterest 月還款利息
 * @return
 */
 public static BigDecimal monthPrincipal(BigDecimal monthRepayment, BigDecimal monthInterest){
 //月還款總額-月還款利息
 return monthRepayment.subtract(monthInterest).setScale(MoneyUtils.MONEYSHOWSCALE, MoneyUtils.SAVEROUNDINGMODE);
 }
}

先息后本

import java.math.BigDecimal;

  /**
  * <p>Title: 先息后本還款方式工具類型</p>
  */
  public class BIAPPUtils extends RepaymentUtils {

    /**
    * <p>Description: 月還款利息 貸款本金×月利率 </p>
    * @param loan 貸款本金
    * @param monthlyInterestRate 月利率
    * @return
    */
    public static BigDecimal monthlyInterest(BigDecimal loan, BigDecimal monthlyInterestRate){
      return loan.multiply(monthlyInterestRate, MoneyUtils.MATHCONTEXT);
    }
    /**
    * <p>Description: 還款總利息 貸款本金×月利率×期數(shù)</p>
    * @param loan 貸款本金
    * @param monthlyInterestRate 月利率
    * @param number 期數(shù)
    * @return
    */
    public static BigDecimal interest(BigDecimal loan, BigDecimal monthlyInterestRate, int number){
      return loan.multiply(monthlyInterestRate).multiply(new BigDecimal(number), MoneyUtils.MATHCONTEXT);
    }
    /**
    * <p>Description: 月還款額</p>
    * @param loan 貸款本金
    * @param monthlyInterestRate 月利率
    * @param amount 期數(shù)
    * @param curNumber 當(dāng)前期數(shù)
    * @return
    */
    public static BigDecimal monthlyRepayment(BigDecimal loan, BigDecimal monthlyInterestRate, int amount, int curNumber){
        BigDecimal monthlyInterest = monthlyInterest(loan, monthlyInterestRate);
        if(amount == curNumber){
          return monthlyInterest.add(loan, MoneyUtils.MATHCONTEXT);//最后月還款額
        }else{
          return monthlyInterest;
        }
    }
  }

*金額計算工具類

import java.math.BigDecimal;
  import java.math.MathContext;
  import java.math.RoundingMode;
  import java.text.NumberFormat;

  public class MoneyUtils {
    /**
    * 標(biāo)度(小數(shù)位數(shù))
    */
    public static final int SCALE = 10;

    /**
    * 金錢顯示標(biāo)度(小數(shù)位數(shù))
    */
    public static final int MONEYSHOWSCALE = 2;

    /**
    * 利率顯示標(biāo)度(小數(shù)位數(shù))
    */
    public static final int INTERESTRATESHOWSCALE = 4;

    /**
    * 精度
    */
    public static final int PRECISION = 30;

    /**
    * 保存舍入規(guī)則
    */
    public static final RoundingMode SAVEROUNDINGMODE = RoundingMode.HALF_UP;

    /**
    * 是否舍去小數(shù)點最后的零
    */
    public static boolean STRIPTRAILINGZEROS = true;

    /**
    * 運算上下文(設(shè)置精度、舍入規(guī)則)
    */
    public static final MathContext MATHCONTEXT = new MathContext(PRECISION, SAVEROUNDINGMODE);

    /**
    * 每年天數(shù)
    */
    public static final String YEARDAYS = "360";

    /**
    * 每年月數(shù)
    */
    public static final String YEARMOTHS = "12";

    /**
    * 每月天數(shù)
    */
    public static final String MOTHDAYS = "30";

    /**
    * 數(shù)字“1”
    */
    public static final BigDecimal ONE = new BigDecimal(1);

    /**
    * 數(shù)字“100”
    */
    public static final BigDecimal HUNDRED = new BigDecimal(100);

    /**
    * 數(shù)字“0.01”
    */
    public static final BigDecimal ONEHUNDREDTH = new BigDecimal(0.01);

    public static BigDecimal newBigDecimal(String str){
      return (str == null || str.trim().isEmpty()) ? BigDecimal.ZERO : new BigDecimal(str);
    }

    /**
    * <p>Description: 加法返回格式化結(jié)果數(shù)字</p>
    * @param addend
    * @param augend
    * @return
    */
    public static BigDecimal add(BigDecimal addend, BigDecimal augend){
      return formatMoney(addend.add(augend, MATHCONTEXT));
    }

   /**
    * <p>Description: 加法返回格式化結(jié)果數(shù)字</p>
    * @param addend
    * @param augend
    * @return
    */
    public static BigDecimal add(String addend, String augend){
      BigDecimal decimalAddend = newBigDecimal(addend);
      BigDecimal decimalAugend = newBigDecimal(augend);
      return formatMoney(decimalAddend.add(decimalAugend, MATHCONTEXT));
    }

    /**
    * <p>Description: 加法返回格式化結(jié)果字符串</p>
    * @param addend
    * @param augend
    * @return
    */
    public static String addToString(BigDecimal addend, BigDecimal augend){
      return formatToString(addend.add(augend, MATHCONTEXT));
    }

    /**
    * <p>Description: 加法返回格式化結(jié)果字符串</p>
    * @param addend
    * @param augend
    * @return
    */
    public static String addToString(String addend, String augend){
      BigDecimal decimalAddend = newBigDecimal(addend);
      BigDecimal decimalAugend = newBigDecimal(augend);
      return formatToString(decimalAddend.add(decimalAugend, MATHCONTEXT));
    }

    /**
    * <p>Description: 減法返回格式化結(jié)果數(shù)字</p>
    * @param minuend
    * @param subtrahend
    * @return
    */
    public static BigDecimal subtract(BigDecimal minuend, BigDecimal subtrahend){
      return formatMoney(minuend.subtract(subtrahend, MATHCONTEXT));
    }

    /**
    * <p>Description: 減法返回格式化結(jié)果數(shù)字</p>
    * @param minuend
    * @param subtrahend
    * @return
    */
    public static BigDecimal subtract(String minuend, String subtrahend){
      BigDecimal decimalMinuend = newBigDecimal(minuend);
      BigDecimal decimalSubtrahend = newBigDecimal(subtrahend);
      return formatMoney(decimalMinuend.subtract(decimalSubtrahend, MATHCONTEXT));
    }

    /**
    * <p>Description: 減法返回格式化結(jié)果字符串</p>
    * @param minuend
    * @param subtrahend
    * @return
    */
    public static String subtractToString(BigDecimal minuend, BigDecimal subtrahend){
      return formatToString(minuend.subtract(subtrahend, MATHCONTEXT));
    }
    /**
    * <p>Description: 減法返回格式化結(jié)果字符串</p>
    * @param minuend
    * @param subtrahend
    * @return
    */
    public static String subtractToString(String minuend, String subtrahend){
      BigDecimal decimalMinuend = newBigDecimal(minuend);
      BigDecimal decimalSubtrahend = newBigDecimal(subtrahend);
      return formatToString(decimalMinuend.subtract(decimalSubtrahend, MATHCONTEXT));
    }

    /**
    * <p>Description: 乘法返回格式化結(jié)果數(shù)字</p>
    * @param multiplier
    * @param multiplicand
    * @return
    */
    public static BigDecimal multiply(BigDecimal multiplier, BigDecimal multiplicand){
      return formatMoney(multiplier.multiply(multiplicand, MATHCONTEXT));
    }

    /**
    * <p>Description: 乘法返回格式化結(jié)果數(shù)字</p>
    * @param multiplier
    * @param multiplicand
    * @return
    */
    public static BigDecimal multiply(String multiplier, String multiplicand){
      BigDecimal decimalMultiplier = newBigDecimal(multiplier);
      BigDecimal decimalMultiplicand = newBigDecimal(multiplicand);
      return formatMoney(decimalMultiplier.multiply(decimalMultiplicand, MATHCONTEXT));
    }

    /**
    * <p>Description: 乘法返回格式化結(jié)果字符串</p>
    * @param multiplier
    * @param multiplicand
    * @return
    */
    public static String multiplyToString(BigDecimal multiplier, BigDecimal multiplicand){
      return formatToString(multiplier.multiply(multiplicand, MATHCONTEXT));
    }
    /**
    * <p>Description: 乘法返回格式化結(jié)果字符串</p>
    * @param multiplier
    * @param multiplicand
    * @return
    */
    public static String multiplyToString(String multiplier, String multiplicand){
      BigDecimal decimalMultiplier = newBigDecimal(multiplier);
      BigDecimal decimalMultiplicand = newBigDecimal(multiplicand);
      return formatToString(decimalMultiplier.multiply(decimalMultiplicand, MATHCONTEXT));
    }

    /**
    * <p>Description: 除法返回格式化結(jié)果數(shù)字</p>
    * @param dividend
    * @param divisor
    * @return
    */
    public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor){
      return formatMoney(dividend.divide(divisor, MATHCONTEXT));
    }
    /**
    * <p>Description: 除法返回格式化結(jié)果數(shù)字</p>
    * @param dividend
    * @param divisor
    * @return
    */
    public static BigDecimal divide(String dividend, String divisor){
      BigDecimal decimalDividend = newBigDecimal(dividend);
      BigDecimal decimalDivisor = newBigDecimal(divisor);
      return formatMoney(decimalDividend.divide(decimalDivisor, MATHCONTEXT));
    }

    /**
    * <p>Description: 除法返回格式化結(jié)果字符串</p>
    * @param dividend
    * @param divisor
    * @return
    */
    public static String divideToString(BigDecimal dividend, BigDecimal divisor){
      return formatToString(dividend.divide(divisor, MATHCONTEXT));
    }

    /**
    * <p>Description: 除法返回格式化結(jié)果字符串</p>
    * @param dividend
    * @param divisor
    * @return
    */
    public static String divideToString(String dividend, String divisor){
      BigDecimal decimalDividend = newBigDecimal(dividend);
      BigDecimal decimalDivisor = newBigDecimal(divisor);
      return formatToString(decimalDividend.divide(decimalDivisor, MATHCONTEXT));
    }
    /**
    * <p>Description: 月利率計算</p>
    * @param yearInterestRate
    * @return
    */
    public static BigDecimal monthInterestRate(BigDecimal yearInterestRate){
      BigDecimal dayInterestRate = MoneyUtils.divide(yearInterestRate, YEARDAYS).setScale(5, RoundingMode.CEILING);
      System.err.println(dayInterestRate);
      BigDecimal monthInterestRate = dayInterestRate.multiply(newBigDecimal(MOTHDAYS));
      System.err.println(monthInterestRate);
      return monthInterestRate;
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化金額保存</p>
    * @param result
    * @return
    */
    public static BigDecimal formatMoney(BigDecimal result){
      return result.setScale(SCALE, SAVEROUNDINGMODE);
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化金額顯示</p>
    * @param resultStr 要格式化的數(shù)
    * @param multiple 乘以的倍數(shù)
    * @return
    */
    public static String formatMoneyToShow(String resultStr, BigDecimal multiple){
      BigDecimal result = newBigDecimal(resultStr);
      return MoneyUtils.formatToString(MoneyUtils.formatMoneyToShow(result, multiple));
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化金額顯示</p>
    * @param result 要格式化的數(shù)
    * @param multiple 乘以的倍數(shù)
    * @return
    */
    public static BigDecimal formatMoneyToShow(BigDecimal result, BigDecimal multiple){
      return result.multiply(multiple).setScale(MONEYSHOWSCALE, SAVEROUNDINGMODE);
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化利率顯示</p>
    * @param result 要格式化的數(shù)
    * @param multiple 乘以的倍數(shù)
    * @return
    */
    public static BigDecimal formatInterestRateToShow(BigDecimal result, BigDecimal multiple){
      return result.multiply(multiple).setScale(INTERESTRATESHOWSCALE, SAVEROUNDINGMODE);
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化顯示</p>
    * @param result 要格式化的數(shù)
    * @param scale 顯示標(biāo)度(小數(shù)位數(shù))
    * @return
    */
    public static BigDecimal formatToShow(BigDecimal result, int scale){
      return result.setScale(scale, SAVEROUNDINGMODE);
    }

    /**
    * <p>Description: 格式化為字符串,進行去零不去零操作</p>
    * @param result
    * @return
    */
    public static String formatToString(BigDecimal result){
      if(result == null){
        return "";
      }else{
        return STRIPTRAILINGZEROS ? result.stripTrailingZeros().toPlainString() : result.toPlainString();
      }
    }

    /**
    * <p>Description: 按既定小數(shù)位數(shù)格式化為貨幣格式</p>
    * @param result
    * @return
    */
    public static String formatToCurrency(BigDecimal result){
      BigDecimal temp = result.divide(HUNDRED, SAVEROUNDINGMODE);
      NumberFormat numberFormat = NumberFormat.getCurrencyInstance();
      return numberFormat.format(STRIPTRAILINGZEROS ? temp.stripTrailingZeros() : temp);
    }

    public static String formatToPercent(BigDecimal result){
      BigDecimal temp = result.divide(HUNDRED, SAVEROUNDINGMODE);
      NumberFormat numberFormat = NumberFormat.getPercentInstance();
      return numberFormat.format(STRIPTRAILINGZEROS ? temp.stripTrailingZeros() : temp);
    }

    /** 
    * <p>Description:格式化數(shù)字為千分位顯示; </p>
    * @param text 
    * @return 
    */ 
    public static String fmtMicrometer(String text){ 
      DecimalFormat df = null; 
      if(text.indexOf(".") > 0) { 
        if(text.length() - text.indexOf(".")-1 == 0){ 
          df = new DecimalFormat("###,##0."); 
        }else if(text.length() - text.indexOf(".")-1 == 1){ 
          df = new DecimalFormat("###,##0.0"); 
        }else { 
          df = new DecimalFormat("###,##0.00"); 
        } 
      }else{ 
        df = new DecimalFormat("###,##0.00"); 
      } 
      double number = 0.0; 
      try { 
        number = Double.parseDouble(text); 
      } catch (Exception e) { 
        number = 0.0; 
      } 
      return df.format(number); 
    }
  }

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持創(chuàng)新互聯(lián)!

網(wǎng)頁題目:java中每月等額與先息后本計算
本文來源:http://jinyejixie.com/article22/jjphjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、手機網(wǎng)站建設(shè)、微信小程序品牌網(wǎng)站設(shè)計、移動網(wǎng)站建設(shè)、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
麻阳| 海安县| 上虞市| 龙南县| 论坛| 漳平市| 阳朔县| 班玛县| 淮北市| 芦山县| 罗源县| 陆良县| 罗江县| 光山县| 宁波市| 清水河县| 庆元县| 江山市| 海淀区| 海淀区| 惠州市| 莲花县| 甘孜| 余庆县| 依兰县| 禄劝| 沾益县| 和龙市| 安西县| 洪湖市| 长子县| 枝江市| 澄迈县| 南宫市| 南昌市| 安新县| 克东县| 彰武县| 定陶县| 嘉祥县| 防城港市|