Results 1 to 4 of 4
  1. #1
    ellhar is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default 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. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,421
    Rep Power
    20

    Default

    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. #3
    ellhar is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    So that isn't a Java exception?

  4. #4
    ellhar is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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

Similar Threads

  1. Using BigDecimal
    By doymand in forum New To Java
    Replies: 2
    Last Post: 10-30-2010, 10:25 AM
  2. All possible way to divide a number?
    By bobocheez in forum New To Java
    Replies: 4
    Last Post: 09-24-2010, 03:24 AM
  3. Divide and Conquer@Array...im becoming crazy!
    By wyldstyle in forum New To Java
    Replies: 0
    Last Post: 08-23-2009, 10:20 PM
  4. Replies: 2
    Last Post: 08-04-2009, 01:35 AM
  5. How to divide code in classes?
    By hendrix79 in forum New To Java
    Replies: 2
    Last Post: 12-10-2008, 06:36 PM

Tags for this Thread

Posting Permissions

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