Java Data Type Tutorial - Java BigDecimal .subtract (BigDecimal subtrahend)








Syntax

BigDecimal.subtract(BigDecimal subtrahend) has the following syntax.

public BigDecimal subtract(BigDecimal subtrahend)

Example

In the following code shows how to use BigDecimal.subtract(BigDecimal subtrahend) method.

/*from ww  w  .ja  v a  2  s.  c  o  m*/
import java.math.BigDecimal;

public class Main {

  public static void main(String[] args) {

    BigDecimal bg1 = new BigDecimal("100.123");
    BigDecimal bg2 = new BigDecimal("50.56");

    // subtract bg1 with bg2 and assign result to bg3
    BigDecimal bg3 = bg1.subtract(bg2);

    String str = "The Result of Subtraction is " + bg3;

    // print bg3 value
    System.out.println(str);
  }
}

The code above generates the following result.