- Java.math 包扩展
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigDecimal.negate() 方法
说明
java.math.BigDecimal.negate() 返回一个 BigDecimal,它的值为 (-this),而它的刻度为 this.scale()。
声明
以下是 java.math.BigDecimal.negate() 方法的声明。
public BigDecimal negate()
参数
不适用
返回值
此方法返回对象的负值,即 -this。
异常
不适用
示例
以下示例显示了 math.BigDecimal.negate() 方法的使用。
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("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.1264 is -40.1264
java_math_bigdecimal.htm
广告