- Java.math 包其他内容
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigDecimal.pow() 方法
描述
java.math.BigDecimal.pow(int n) 将返回一个 BigDecimal,其值为 (thisn),该幂计算十分精确,无限制。
该参数 n 必须在 0 到 999999999(包含)的范围内。ZERO.pow(0) 返回 ONE。
声明
以下是 java.math.BigDecimal.pow() 方法的声明。
public BigDecimal pow(int n)
参数
n − 将此 BigDecimal 提升到的幂。
返回值
此方法返回提升至幂 n 的 BigDecimal 对象的值,即 thisn。
异常
ArithmeticException − 如果 n 超出范围。
示例
以下示例演示了 math.BigDecimal.pow() 方法的使用。
package com.tutorialspoint;
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
java_math_bigdecimal.htm
广告