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