BigDecimal.negate(MathContext mc) has the following syntax.
public BigDecimal negate(MathContext mc)
In the following code shows how to use BigDecimal.negate(MathContext mc) method.
//w ww . jav a 2 s . com import java.math.BigDecimal; import java.math.MathContext; public class Main { public static void main(String[] args) { MathContext mc = new MathContext(4);// 4 precision // assign value to bg1 BigDecimal bg1 = new BigDecimal("123.1234"); // assign negate value of bg1 to bg2 using mc BigDecimal bg2 = bg1.negate(mc); System.out.println(bg2); } }
The code above generates the following result.