Java-math-bigdecimal-unscaledvalue

提供:Dev Guides
移動先:案内検索

Java.math.BigDecimal.unscaledValue()メソッド

説明

  • java.math.BigDecimal.unscaledValue()*は、値がこのBigDecimalのスケーリングされていない値であるBigIntegerを返します。 (計算(this * 10 ^ this.scale()^)。)

宣言

次に、* java.math.BigDecimal.unscaledValue()*メソッドの宣言を示します。

public BigInteger unscaledValue()

パラメーター

NA

戻り値

このメソッドは、このBigDecimalのスケーリングされていない値を返します。

例外

NA

次の例は、math.BigDecimal.unscaledValue()メソッドの使用法を示しています。

package com.finddevguides;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

     //create 2 BigDecimal objects
      BigDecimal bg1, bg2;

     //create 2 BigInteger objects
      BigInteger bi1, bi2;

      bg1 = new BigDecimal("123.12");
      bg2 = new BigDecimal("-245.03");

     //assign unscaledValue of bg1,bg2 to bi1,bi2
      bi1 = bg1.unscaledValue();
      bi2 = bg2.unscaledValue();

      String str1 = "The Unscaled Value of " + bg1 + " is " + bi1;
      String str2 = "The Unscaled Value of " + bg2 + " is " + bi2;

     //print bi1, bi2 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

上記のプログラムをコンパイルして実行すると、次の結果が生成されます-

The Unscaled Value of 123.12 is 12312
The Unscaled Value of -245.03 is -24503