Java Data Type Tutorial - Java BigDecimal.plus(MathContext mc)








Syntax

BigDecimal.plus(MathContext mc) has the following syntax.

public BigDecimal plus(MathContext mc)

Example

In the following code shows how to use BigDecimal.plus(MathContext mc) method.

/*from w  ww  . j ava 2  s. c  o m*/
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("-333.3454");

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

    // perform plus on bg1 using mc
    BigDecimal bg2 = bg1.plus(mc);

    System.out.println(bg2);
  }
}

The code above generates the following result.