BigDecimal.ROUND_HALF_DOWN : BigDecimal « java.math « Java by API






BigDecimal.ROUND_HALF_DOWN

 

import java.math.BigDecimal;

public class Main {
  public static void main(String args[]) {
    BigDecimal rate = new BigDecimal(".03251234");
    BigDecimal months = new BigDecimal("12");
    BigDecimal monthlyRate = rate
        .divide(months, BigDecimal.ROUND_HALF_DOWN);
    System.out.println("Annual rate : " + rate);
    System.out.println("Monthly rate: " + monthlyRate);
    BigDecimal balance = new BigDecimal("10000.0000");
    for (int i = 0; i < 12; i++) {
      BigDecimal interest = balance.multiply(monthlyRate);
      balance = balance.add(interest);
      System.out.println("Balance: " + balance);
    }
  }
}
     

   
  








Related examples in the same category

1.BigDecimal.ROUND_DOWN
2.BigDecimal.ROUND_HALF_UP
3.BigDecimal.ROUND_UP
4.new BigDecimal(String val)
5.BigDecimal: abs()
6.BigDecimal: add(BigDecimal augend)
7.BigDecimal: doubleValue()
8.BigDecimal: divide(BigDecimal divisor)
9.BigDecimal: divide(BigDecimal divisor, int roundingMode)
10.BigDecimal: equals(Object x)
11.BigDecimal: max(BigDecimal val)
12.BigDecimal: min(BigDecimal val)
13.BigDecimal: multiply(BigDecimal multiplicand)
14.BigDecimal: negate()
15.BigDecimal: pow(int n)
16.BigDecimal: remainder(BigDecimal divisor)
17.BigDecimal: setScale(int newScale, int roundingMode)
18.BigDecimal: subtract(BigDecimal subtrahend)
19.BigDecimal: valueOf(long val)