Java-math-bigdecimal-pow

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

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

説明

  • java.math.BigDecimal.pow(int n)*は、値が(this ^ n ^)であるBigDecimalを返します。累乗は、精度が無制限に正確に計算されます。

パラメーターnは、0から999999999までの範囲でなければなりません。 ZERO.pow(0)はONEを返します。

宣言

以下は* java.math.BigDecimal.pow()*メソッドの宣言です。

public BigDecimal pow(int n)

パラメーター

*n* -このBigDecimalを上げる力。

戻り値

このメソッドは、BigDecimalオブジェクトの値をnの累乗、つまりthis ^ n ^で返します。

例外

*ArithmeticException* -nが範囲外の場合。

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

package com.finddevguides;

import java.math.*;

public class BigDecimalDemo {

   public static void main(String[] args) {

     //create 2 BigDecimal Objects
      BigDecimal bg1, bg2;

      bg1 = new BigDecimal("2.17");

     //apply pow method on bg1
      bg2 = bg1.pow(3);

      String str = "The value of " + bg1 + " to the power of 3 is " + bg2;

     //print bg2 value
      System.out.println( str );
   }
}

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

The value of 2.17 to the power of 3 is 10.218313