Methods used to do calculation


    BigDecimal  abs()
    BigDecimal  abs(MathContext mc)
    BigDecimal  add(BigDecimal augend)
    BigDecimal  add(BigDecimal augend, MathContext mc)
    BigDecimal  divide(BigDecimal divisor)
    BigDecimal  divide(BigDecimal divisor, int roundingMode)
    BigDecimal  divide(BigDecimal divisor, int scale, int roundingMode)
    BigDecimal  divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
    BigDecimal  divide(BigDecimal divisor, MathContext mc)
    BigDecimal  divide(BigDecimal divisor, RoundingMode roundingMode)
    BigDecimal[]divideAndRemainder(BigDecimal divisor)
    BigDecimal[]divideAndRemainder(BigDecimal divisor, MathContext mc)
    BigDecimal  divideToIntegralValue(BigDecimal divisor)
    BigDecimal  divideToIntegralValue(BigDecimal divisor, MathContext mc)
    BigDecimal  max(BigDecimal val)
    BigDecimal  min(BigDecimal val)
    BigDecimal  multiply(BigDecimal multiplicand)
    BigDecimal  multiply(BigDecimal multiplicand, MathContext mc)
    BigDecimal  negate()
    BigDecimal  negate(MathContext mc)
    BigDecimal  plus()
    BigDecimal  plus(MathContext mc)
    BigDecimal  pow(int n)
    BigDecimal  pow(int n, MathContext mc)
    BigDecimal  remainder(BigDecimal divisor)
    BigDecimal  remainder(BigDecimal divisor, MathContext mc)
    BigDecimal  round(MathContext mc)
    BigDecimal  scaleByPowerOfTen(int n)
    BigDecimal  subtract(BigDecimal subtrahend)
    BigDecimal  subtract(BigDecimal subtrahend, MathContext mc)

import java.math.BigDecimal;
 

public class Main {
 
    public static void main(String[] args) {
        BigDecimal first = new BigDecimal(-1f);
        System.out.println(first);
        System.out.println(first.abs());
    }
}

The output:


-1
1

import java.math.BigDecimal;
 

public class Main {
 
    public static void main(String[] args) {
        BigDecimal first = new BigDecimal(-1f);
        BigDecimal second = new BigDecimal(10f);
 
        BigDecimal result = first.add(second); 
        System.out.println(result);
    }
}

The output:


9
Home 
  Java Book 
    Essential Classes  

BigDecimal:
  1. BigDecimal class
  2. Constants for One, Ten and Zero
  3. Rounding mode
  4. Create BigDecimals
  5. Methods used to do calculation
  6. Convert BigDecimal to primitive data types
  7. Compare two BigDecimal
  8. Move decimal point
  9. Scale and precision
  10. Convert BigDecimal to String
  11. Remove the trailing zeros
  12. Convert double and long to BigDecimal
  13. Calculating Euler's number e with BigDecimal