Results 1 to 2 of 2

Thread: Help with java.math.BigDecimal.divide

  1. #1
    ellhar is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Mar 2011
    Posts
    2
    Reputation
    0

    Help with java.math.BigDecimal.divide

    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 = 60324762316236124242239726873638336018154208503434 42563976617901959446852491785214562114886583038846 16225443523975498193721650575179822647801351393175 36553882418383705612030689636993014197004498494888 25211202575674030028852126452605313960394838157847 22825993921626961326025135533966900021958296664224 15891748281084776484166425988098535284129222131481 41476059585228615644978557227745284704842625785068 15029292116856464192210904093847926408616181250

    temp1 = 14019794252912799840308853347835564344285452963038 77509391159647746928645079044900154959035332308386 10807504452415706186980483480394059626374257083559 78463675014403954557959466890632215289049473866724 37050974090868999353706113579833335585631516743660 61980065529552537963005970613764925196109626945217 55218800777568856026580101237251182637007824894694 1909602194221043956157513876644


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

    Many thanks

    E

  2. #2
    ellhar is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Mar 2011
    Posts
    2
    Reputation
    0
    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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking