Java Data Type Tutorial - Java BigDecimal .divideAndRemainder (BigDecimal divisor, MathContext mc)








Syntax

BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) has the following syntax.

public BigDecimal [] divideAndRemainder(BigDecimal divisor,    MathContext mc)

Example

In the following code shows how to use BigDecimal.divideAndRemainder(BigDecimal divisor, MathContext mc) method.

/*w ww  .  j  ava2  s.  co  m*/
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("143.145");
    BigDecimal bg2 = new BigDecimal("10.01");

    MathContext mc = new MathContext(2);

    BigDecimal bg[] = bg1.divideAndRemainder(bg2, mc);

    System.out.println("Quotient is " + bg[0]);
    System.out.println("Remainder is " + bg[1]);
  }
}

The code above generates the following result.