Java BigDecimal.negate(MathContext mc)

Syntax

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

public BigDecimal negate(MathContext mc)

Example

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


// w  w w. j  a va 2s  .co m
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.





















Home »
  Java Tutorial »
    java.math »




BigDecimal
BigInteger