java.math.BigDecimal.negate() 返回一个BigDecimal,其值是(-this),其标度是this.scale()。
声明
以下是java.math.BigDecimal.negate()方法的声明
public BigDecimal negate()
参数
-
NA
返回值
此方法返回的对象的负值,即: -this
异常
-
NA
例子
下面的例子显示math.BigDecimal.negate()方法的用法
package com.yiibai; 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("40.1264"); // assign negate value of bg1 to bg2 bg2 = bg1.negate(); String str = "Negated value of " + bg1 + " is "+ bg2; // print bg1 and bg2 values System.out.println( str ); } }
让我们编译和运行上面的程序,这将产生以下结果:
Negated value of 40.1234 is -40.1264