Java BigDecimal.add(BigDecimal augend, MathContext mc)
Syntax
BigDecimal.add(BigDecimal augend, MathContext mc) has the following syntax.
public BigDecimal add(BigDecimal augend, MathContext mc)
Example
In the following code shows how to use BigDecimal.add(BigDecimal augend, MathContext mc) method.
//from w w w. j a v a 2 s. co m
import java.math.BigDecimal;
import java.math.MathContext;
public class Main {
public static void main(String[] args) {
BigDecimal bg1 = new BigDecimal("12.345");
BigDecimal bg2 = new BigDecimal("23.456");
System.out.println("Object Value is " + bg1);
System.out.println("Augend value is " + bg2);
// create MathContext object with 4 precision
MathContext mc = new MathContext(4);
// perform add operation on bg1 with augend bg2 and context mc
BigDecimal bg3 = bg1.add(bg2, mc);
System.out.println("Result is " + bg3);
}
}
The code above generates the following result.