Java BigDecimal unscaledValue()

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()

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程