Java的BigDecimal.power(BigDecimal指数):是否有Java库可以做到这一点? [英] Java's BigDecimal.power(BigDecimal exponent): Is there a Java library that does it?
问题描述
Java的 BigDecimal.pow(int)
方法只接受整数参数,没有 BigDecimal
参数。
Java's BigDecimal.pow(int)
method only accepts an integer parameter, no BigDecimal
parameter.
是否有像Apache的commons-lang这样的库支持 BigDecimal.pow(BigDecimal)
?它应该可以计算1.21.pow(0.5)
返回1.1
。
Is there a library, like Apache's commons-lang, that supports BigDecimal.pow(BigDecimal)
? It should be able to do calculate "1.21".pow("0.5")
to return "1.1"
.
推荐答案
有一个 Math.BigDecimal实现核心数学函数,源代码可从康奈尔大学图书馆获得 here (您也可以将该库下载为 tar.gz )。以下是使用库的示例:
There is a Math.BigDecimal implementation of core mathematical functions with source code available from the Cornell University Library here (also you can download the library as a tar.gz). Here is a sample of the library use:
import org.nevec.rjm.*;
import java.math.BigDecimal;
public class test {
public static void main(String... args) {
BigDecimal a = new BigDecimal("1.21");
BigDecimal b = new BigDecimal("0.5");
System.out.println(BigDecimalMath.pow(a, b).toString());
}
}
打印出来:
1.1
更新
许可证信息现已在2015年5月更新中清除:
Update
The license information is now clear in the May 2015 update:
完整源代码在LGPL v3.0下提供。
The full source code is made available under the LGPL v3.0.
这篇关于Java的BigDecimal.power(BigDecimal指数):是否有Java库可以做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!