Do math operation for BigDecimal : BigDecimal « Data Type « Java Tutorial






import java.math.BigDecimal;

public class Main {
  public static void main(String[] args) {
    BigDecimal decimalA = new BigDecimal("123456789012345");
    BigDecimal decimalB = new BigDecimal("10");

    decimalA = decimalA.add(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.multiply(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.subtract(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.divide(decimalB);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.pow(2);
    System.out.println("decimalA = " + decimalA);

    decimalA = decimalA.negate();
    System.out.println("decimalA = " + decimalA);
  }
}








2.46.BigDecimal
2.46.1.Round a double
2.46.2.Create Big Decimal Values via a long
2.46.3.Create a BigDecimal vis string
2.46.4.Multiply one BigDecimal to another BigDecimal
2.46.5.Subtract from one BigDecimal another BigDecimal
2.46.6.Divide one BigDecimal from another BigDecimal
2.46.7.Negate a BigDecimal
2.46.8.Setting the Decimal Place of a Big Decimal Value
2.46.9.Truncates the big decimal value
2.46.10.Do math operation for BigDecimal
2.46.11.Operate with big decimal values
2.46.12.Create Big Decimal Values via a string
2.46.13.Convert Object to BigDecimal