1. Member
Join Date
Mar 2011
Posts
3
Rep Power
0

## Divide bigdecimal again

Hi Java world,

I have a web page that is calculating some statistics. As such I need to work with some very large numbers. I've pulled in the dll allowing me to work with BigInteger and BigDecimal.

however I am able to calculate all my numbers (as these are multiplication) but when it comes producing the required result I need to divide the 2 large decimals without rounding I get an exception saying

{"ROUND_UNNECESSARY when fraction is non-zero"}

Dim comb3 As New java.math.BigInteger(0)
Dim toptot As New java.math.BigInteger(0)
Dim pval As New java.math.BigDecimal(0)

TRYING TO ALLOW FLAOTING POINT ANSWER BY CONVERTING BIG INTS TO DECIMALS
Dim temp As New java.math.BigDecimal(toptot.tostring & ".0")
Dim temp1 As New java.math.BigDecimal(comb3.tostring & ".0")

'Code fails at this point
pval = temp.divide(temp1, java.math.BigDecimal.ROUND_UNNECESSARY)

temp = 60324762316236124242239726873638336018154208503434 42563976617901959446852491785214562114886583038846 16225443523975498193721650575179822647801351393175 36553882418383705612030689636993014197004498494888 25211202575674030028852126452605313960394838157847 22825993921626961326025135533966900021958296664224 15891748281084776484166425988098535284129222131481 41476059585228615644978557227745284704842625785068 15029292116856464192210904093847926408616181250.0

temp1 = 14019794252912799840308853347835564344285452963038 77509391159647746928645079044900154959035332308386 10807504452415706186980483480394059626374257083559 78463675014403954557959466890632215289049473866724 37050974090868999353706113579833335585631516743660 61980065529552537963005970613764925196109626945217 55218800777568856026580101237251182637007824894694 1909602194221043956157513876644.0

The code executes if I employ onther rounding strategy but I in effect lose the answer I'm chasing.

I've tried catching the error and performing double division but numbers are too large.

I've been stuck on this for a while so help very much appreciated.

E

2. Dim comb3 As ...
What's that? VB? This is a Java forum.

Your cross post may fare better.
Help with java.math.BigDecimal.divide

db

3. Member
Join Date
Mar 2011
Posts
3
Rep Power
0
So that isn't a Java exception?

4. Member
Join Date
Mar 2011
Posts
3
Rep Power
0
For any interested the solution to my non Java problem was declaring the number of figures in the divide result

so

pval = temp.divide(temp1,20, java.math.BigDecimal.ROUND_UP)

Cheers

E