Java BigDecimal 替代库
这可能听起来特别奇怪,但我必须针对 GCJ 编译几个新代码;不支持 Java 的 BigDecimal。
我正在寻找的是 java.math.BigDecimal 的替代品。
有人能指出我正确的方向吗?
谢谢!
This may strike as particularly odd but I must compile several new code against GCJ; that doesn't support Java's BigDecimal.
What I'm looking for is an alternative to java.math.BigDecimal.
Can anyone point me in the right direction?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来 gcj 是针对 JDK 1.4.2 进行编译的,该版本仅提供
setScale(int scale, int roundingMode)
和setScale(int scale)
。您尝试编译的代码似乎是为 JDK 1.5.0 及更高版本编写的。在 JDK 1.5.0 中,除了其他两个之外,您还可以获得 setScale(int newScale, RoundingMode roundingMode) 。
您可以查看 gcj 是否有更新,使其可以使用 1.5。从gcj网站来看,我不认为情况如此。它表示当前版本“支持大部分 1.4 库以及一些 1.5 新增内容”。
您的另一个选择是重写代码,以便对
setScale(int newScale, RoundingMode roundingMode)
的调用替换为setScale(int scale, int roundingMode)
。在 1.5.0 中,您可以使用RoundingMode
来指定roundingMode
的整数值(使用BigDecimal
中的静态整数)枚举(仍保留旧方法以实现向后兼容性)。因此,在您的代码中,您将使用
BigDecimal.ROUND_CEILING
,而不是RoundingMode.CEILING
。It looks like gcj is compiling against JDK 1.4.2, which only provides
setScale(int scale, int roundingMode)
andsetScale(int scale)
.The code you're trying to compile seems to have been written for JDK 1.5.0 and above. In JDK 1.5.0, you get
setScale(int newScale, RoundingMode roundingMode)
in addition to the other two.You can see if there is an update to gcj that lets it use 1.5. From looking at the gcj website, I don't see this as the case. It says that the current version "supports most of the 1.4 libraries plus some 1.5 additions."
Your other option is to rewrite the code so that calls to
setScale(int newScale, RoundingMode roundingMode)
are replaced bysetScale(int scale, int roundingMode)
. In 1.5.0, instead of specifing an integer value forroundingMode
(using the static ints inBigDecimal
), you can specify it using theRoundingMode
enum (the older method is still maintained for backwards compatibility).So in your code, instead of
RoundingMode.CEILING
, you would useBigDecimal.ROUND_CEILING
.