Java.math.BigDecimal.plus() 方法
描述
java.math.BigDecimal.plus() 返回一个 BigDecimal,其值为 (+this),其刻度为 this.scale()。
为了与一元减法方法 negate() 对称,包含此方法,它仅返回此 BigDecimal。
声明
以下是 java.math.BigDecimal.plus() 方法的声明。
public BigDecimal plus()
参数
NA
返回值
此方法返回对象值,即 this。
异常
NA
示例
下面的例子展示了 math.BigDecimal.plus() 方法的使用。
package com.tutorialspoint;
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

