BigDecimal plus()

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

描述 (Description)

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

这个简单地返回此BigDecimal的方法包含在一致的减法方法negate()中。

声明 (Declaration)

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

public BigDecimal plus()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回对象值,即this。

异常 (Exception)

NA

例子 (Example)

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

package cn.xnip;
import java.math.*;
public class BigDecimalDemo {
   public static void main(String[] args) {
      // create 2 BigDecimal Objects
      BigDecimal bg1, bg2;
      // assign value to bg1
      bg1 = new BigDecimal("-123.126");
      // assign the result of plus method on bg1 to bg2
      bg2 = bg1.plus();
      String str = "The value of the BigDecimal is " + bg2;
      // print the value of bg2
      System.out.println( str );
   }
}

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

The value of the BigDecimal is -123.126