开发者

Java BigDecimal alternative library

开发者 https://www.devze.com 2023-02-06 13:21 出处:网络
This may strike as particularly odd but I must compile several 开发者_如何学JAVAnew code against GCJ; that doesn\'t support Java\'s BigDecimal.

This may strike as particularly odd but I must compile several 开发者_如何学JAVAnew 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!


It looks like gcj is compiling against JDK 1.4.2, which only provides setScale(int scale, int roundingMode) and setScale(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 by setScale(int scale, int roundingMode). In 1.5.0, instead of specifing an integer value for roundingMode (using the static ints in BigDecimal), you can specify it using the RoundingMode enum (the older method is still maintained for backwards compatibility).

So in your code, instead of RoundingMode.CEILING, you would use BigDecimal.ROUND_CEILING.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号