Example usage for java.math BigDecimal divide

List of usage examples for java.math BigDecimal divide

Introduction

In this page you can find the example usage for java.math BigDecimal divide.

Prototype

public BigDecimal divide(BigDecimal divisor, MathContext mc) 

Source Link

Document

Returns a BigDecimal whose value is (this / divisor) , with rounding according to the context settings.

Usage

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_CEILING);

    System.out.println(bg3);/*from   ww w. j a  va 2s .  co m*/
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_HALF_DOWN);

    System.out.println(bg3);/*from ww w  .ja v  a 2  s .c  o m*/
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_UP);

    System.out.println(bg3);/*from   w ww  .j a  va2  s  .com*/
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_DOWN);

    System.out.println(bg3);/*  w ww. j  av  a 2s  . c o  m*/
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_HALF_EVEN);

    System.out.println(bg3);// www  .j  a va  2 s.co m
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_HALF_UP);

    System.out.println(bg3);/* w  ww.  j a  v  a2 s .  co m*/
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_UNNECESSARY);

    System.out.println(bg3);//from w  w w.  j a  va 2  s  .co  m
}

From source file:Main.java

public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("40");

    BigDecimal bg2 = new BigDecimal("3");

    BigDecimal bg3 = bg1.divide(bg2, BigDecimal.ROUND_FLOOR);

    System.out.println(bg3);/*from   w  ww.j a v  a  2 s  .  c  o  m*/
}

From source file:BigDec.java

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);
    }/*from   w  w w  .ja  va 2s .  co m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BigDecimal bd1 = new BigDecimal("123456789.0123456890");

    // Create via a long
    BigDecimal bd2 = BigDecimal.valueOf(123L);

    bd1 = bd1.divide(bd2, BigDecimal.ROUND_UP);

}