Help with java.math.BigDecimal.divide

ellhar

New member
Joined
Mar 17, 2011
Messages
2
Programming Experience
Beginner
Hi,

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)
Dim temp1 As New java.math.BigDecimal(comb3)


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


temp = 603247623162361242422397268736383360181542085034344256397661790195944685249178521456211488658303884616225443523975498193721650575179822647801351393175365538824183837056120306896369930141970044984948882521120257567403002885212645260531396039483815784722825993921626961326025135533966900021958296664224158917482810847764841664259880985352841292221314814147605958522861564497855722774528470484262578506815029292116856464192210904093847926408616181250

temp1 = 140197942529127998403088533478355643442854529630387750939115964774692864507904490015495903533230838610807504452415706186980483480394059626374257083559784636750144039545579594668906322152890494738667243705097409086899935370611357983333558563151674366061980065529552537963005970613764925196109626945217552188007775688560265801012372511826370078248946941909602194221043956157513876644


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

Many thanks

E
 
For any interested the solution was declaring the number of figures in the divide result

so

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


Cheers

E
 
Back
Top