Java.math.BigDecimal.multiply() Method

Advertisements


Description

The java.math.BigDecimal.multiply(BigDecimal multiplicand) returns a BigDecimal whose value is (this × multiplicand), and whose scale is (this.scale() + multiplicand.scale()).

Declaration

Following is the declaration for java.math.BigDecimal.multiply() method

public BigDecimal multiply(BigDecimal multiplicand)

Parameters

  • multiplicand - value to be multiplied by this BigDecimal

Return Value

This method returns a BigDecimal whose value this * multiplicand

Exception

  • NA

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;

        bg1 = new BigDecimal("2.310");
        bg2 = new BigDecimal("4.620");

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

	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.672200



Advertisements
Advertisements