使用该multiply()
方法在Java中将一个BigDecimal乘以另一个。此方法返回一个BigDecimal,其值为(this×被乘数),其标度为(this.scale()+ multiplicand.scale())。
以下是一个例子-
import java.math.BigDecimal; public class Demo { public static void main(String[] argv) throws Exception { BigDecimal val1 = new BigDecimal("375789755.345778656"); BigDecimal val2 = new BigDecimal("525678755.155778656"); System.out.println("Value 1 = "+val1); System.out.println("Value 2 = "+val2); val2 = val2.multiply(val1); System.out.println("Result (Multiplication) = "+val2); } }
输出结果
Value 1 = 375789755.345778656 Value 2 = 525678755.155778656 Result (Multiplication) = 197544690790463541.417987494305166336
让我们看另一个例子-
import java.math.*; public class Demo { public static void main(String[] args) { BigDecimal bg1, bg2, bg3; bg1 = new BigDecimal("58.98"); bg2 = new BigDecimal("78.89"); bg3 = bg1.multiply(bg2); String str = "Multiplication = " +bg3; System.out.println( str ); } }
输出结果
Multiplication = 4652.9322