Java.math.BigDecimal.multiply() Method
Description
The java.math.BigDecimal.multiply(BigDecimal multiplicand, MathContext mc) returns a BigDecimal whose value is (this × multiplicand), with rounding according to the context settings.
Declaration
Following is the declaration for java.math.BigDecimal.multiply() method.
public BigDecimal multiply(BigDecimal multiplicand, MathContext mc)
Parameters
multiplicand − Value to be multiplied by this BigDecimal.
mc − The context to use.
Return Value
This method returns a BigDecimal whose value this * multiplicand, rounded as necessary.
Exception
ArithmeticException − If the result is inexact but the rounding mode is UNNECESSARY.
Example
The following example shows the usage of math.BigDecimal.multiply() method.
package com.tutorialspoint;
import java.math.*;
public class BigDecimalDemo {
public static void main(String[] args) {
// create 3 BigDecimal objects
BigDecimal bg1, bg2, bg3;
MathContext mc = new MathContext(4); // 4 precision
bg1 = new BigDecimal("2.310");
bg2 = new BigDecimal("4.620");
// multiply bg1 with bg2 using mc
bg3 = bg1.multiply(bg2, mc);
String str = "Multiplication Result is " +bg3;
// print bg3 value
System.out.println( str );
}
}
Let us compile and run the above program, this will produce the following result −
Multiplication Result is 10.67
java_math_bigdecimal.htm
Advertisements