VOOZH about

URL: https://www.geeksforgeeks.org/java/bigdecimal-multiply-method-in-java/

⇱ BigDecimal multiply() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

BigDecimal multiply() Method in Java

Last Updated : 16 Oct, 2019
  1. The java.math.BigDecimal.multiply(BigDecimal multiplicand) is an inbuilt method in java that returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()). Syntax:
    public BigDecimal multiply(BigDecimal multiplicand)
    
    Parameters: This method accepts a single parameter multiplicand of BigDecimal type which refers to the Value to be multiplied by this BigDecimal. Return value: This method returns a BigDecimal whose value this * multiplicand. Below program illustrates the working of the above mentioned method: Program 1:
    Output:
    Multiplication is 769.640
    
    Program 2:
    Output:
    Multiplication is -769.640
    
  2. The java.math.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) is an inbuilt method in Java that returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings. Syntax:
    public BigDecimal multiply(BigDecimal multiplicand, MathContext mc)
    
    Parameters: This method accepts two parameters:
    • multiplicand - This is of BigDecimal type and refers to the value to be multiplied by this BigDecimal.
    • mc - This refers to the context of rounding i.e., up to what decimal place the value is to be rounded off.
    Return value: This method returns a BigDecimal whose value this * multiplicand, rounded as necessary. Program below demonstrates the method: Program 1:
    Output:
    Multiplication is 27.55
    
    Program 2:
Comment