Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java BigDecimal alternative library

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!

like image 534
Frankie Avatar asked Jan 24 '26 05:01

Frankie


1 Answers

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.

like image 80
Vivin Paliath Avatar answered Jan 25 '26 20:01

Vivin Paliath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!