Java BigDecimal .remainder (BigDecimal divisor, MathContext mc)

Syntax

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

public BigDecimal remainder(BigDecimal divisor,   MathContext mc)

Example

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


/*w ww .ja  va 2s  .  c  om*/
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {

  public static void main(String[] args) {

    MathContext mc = new MathContext(2); // 2 precision

    BigDecimal bg1 = new BigDecimal("-144.144");
    BigDecimal bg2 = new BigDecimal("16.12");

    // bg2 divided by bg1 using mc gives bg3 as remainder
    BigDecimal bg3 = bg1.remainder(bg2, mc);

    String str = "The remainder is " + bg3;

    System.out.println(str);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger