Java.math.BigDecimal.multiply() 方法



说明

java.math.BigDecimal.multiply(BigDecimal multiplicand) 返回一个 BigDecimal,其值为 (this × multiplicand),其标度为 (this.scale() + multiplicand.scale())。

声明

以下是 java.math.BigDecimal.multiply() 方法的声明。

public BigDecimal multiply(BigDecimal multiplicand)

参数

multiplicand - 要乘以该 BigDecimal 的值。

返回值

此方法返回一个 BigDecimal,其值为 this * multiplicand。

异常

示例

以下示例显示了如何使用 math.BigDecimal.multiply() 方法。

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 );
   }
}

让我们编译并运行以上程序,它会产生以下结果 -

Multiplication Result is 10.672200
java_math_bigdecimal.htm
广告
© . All rights reserved.