📜  Java中的 BigDecimal unscaledValue()

📅  最后修改于: 2022-05-13 01:55:46.407000             🧑  作者: Mango

Java中的 BigDecimal unscaledValue()

Java.math.BigDecimal.unscaledValue()是Java中的一个内置方法,它返回一个 BigInteger,其值是 BigDecimal 值的未缩放值。该值计算 (this * 10this.scale())。

句法:

public BigInteger unscaledValue()

参数:该方法不接受任何参数。

返回值:此方法返回一个 BigInteger,其值为此 BigDecimal 值的未缩放值。

下面的程序说明了 BigDecimal.unscaledValue() 方法:
方案一:

// 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

方案二:

// 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: Java()