BigDecimal add(BigDecimal augend)

优质
小牛编辑
124浏览
2023-12-01

描述 (Description)

java.math.BigDecimal.add(BigDecimal augend)返回一个BigDecimal,其值为(this + augend),其标度为max(this.scale(),augend.scale())。

声明 (Declaration)

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

public BigDecimal add(BigDecimal augend)

参数 (Parameters)

augend - 要添加到此BigDecimal的值。

返回值 (Return Value)

此方法返回一个BigDecimal对象,其值为this + augend

异常 (Exception)

NA

例子 (Example)

以下示例显示了math.BigDecimal.add()方法的用法。

package cn.xnip;
import java.math.*;
public class BigDecimalDemo {
   public static void main(String[] args) {
      // create 3 BigDecimal objects
      BigDecimal bg1,bg2,bg3;
      // assign value to bg1 and bg2
      bg1 = new BigDecimal("40.732");
      bg2 = new BigDecimal("30.12");
      // print bg1 and bg2 value
      System.out.println("Object Value is " + bg1);
      System.out.println("Augend value is " + bg2);
      // perform add operation on bg1 with augend bg2
      bg3 = bg1.add(bg2);
      // print bg3 value
      System.out.println("Result is " + bg3);
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Object Value is 40.732
Augend value is 30.12
Result is 70.852