取反Java中的BigDecimal值
使用此negate()方法可否定Java中的BigDecimal值。该方法返回一个BigDecimal,其值为(-this),其标度为this.scale()。
以下是一个例子-
示例
import java.math.BigDecimal;
public class Demo {
public static void main(String[] argv) throws Exception {
BigDecimal val1 = new BigDecimal("37578975587");
BigDecimal val2 = new BigDecimal("62567875598");
System.out.println("Value 1 : "+val1);
System.out.println("Value 2 : "+val2);
//除法
val1 = val2.negate();
System.out.println("Result (Negation) = "+val1);
}
}输出结果
Value 1 : 37578975587 Value 2 : 62567875598 Result (Negation) = -62567875598
让我们看另一个例子-
示例
import java.math.*;
public class Demo {
public static void main(String[] args) {
BigDecimal bg1, bg2;
bg1 = new BigDecimal("68.99898");
bg2 = bg1.negate();
String str = "Negated value of " + bg1 + " is "+ bg2;
System.out.println( str );
}
}输出结果
Negated value of 68.99898 is -68.99898
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短