當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java BigDecimal unscaledValue()用法及代碼示例


java.math.BigDecimal.unscaledValue()是java中的一個內置方法,該方法返回BigInteger,其值是BigDecimal值的未縮放值。值進行計算(this * 10this.scale())。

用法:

public BigInteger unscaledValue()

參數:該方法不接受任何參數。


返回值:此方法返回一個BigInteger,其值是此BigDecimal值的未縮放值。

以下示例程序旨在說明BigDecimal.unscaledValue()方法:
示例1:

// Program to illustrate unscaledValue() method of BigDecimal  
  
import java.math.*; 
  
public class Gfg { 
  
    public static void main(String[] args) 
    { 
  
        // Creating 2 BigInteger objects 
        BigInteger i1, i2; 
  
        BigDecimal b1 = new BigDecimal("175.856"); 
        BigDecimal b2 = new BigDecimal("-275.73"); 
  
        // Assigning unscaledValue of BigDecimal objects b1, b2 to i1, i2 
        i1 = b1.unscaledValue(); 
        i2 = b2.unscaledValue(); 
  
        // Printing i1, i2 values 
        System.out.println("The Unscaled Value of " + b1 + " is " + i1); 
        System.out.println("The Unscaled Value of " + b2 + " is " + i2); 
    } 
}
輸出:
The Unscaled Value of 175.856 is 175856
The Unscaled Value of -275.73 is -27573

示例2:

// Program to illustrate unscaledValue() method of BigDecimal  
  
import java.math.*; 
  
public class Gfg { 
  
    public static void main(String[] args) 
    { 
  
        // Creating 2 BigInteger objects 
        BigInteger i1, i2; 
  
        BigDecimal b1 = new BigDecimal("5.5"); 
        BigDecimal b2 = new BigDecimal("-2.73"); 
  
        // Assigning unscaledValue of BigDecimal objects b1, b2 to i1, i2 
        i1 = b1.unscaledValue(); 
        i2 = b2.unscaledValue(); 
  
        // Printing i1, i2 values 
        System.out.println("The Unscaled Value of " + b1 + " is " + i1); 
        System.out.println("The Unscaled Value of " + b2 + " is " + i2); 
    } 
}
輸出:
The Unscaled Value of 5.5 is 55
The Unscaled Value of -2.73 is -273

參考: https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#unscaledValue()



相關用法


注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 BigDecimal unscaledValue() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。