converting integers to BigDecimals

Discussion in 'Java' started by BemusedbyQM, Nov 12, 2005.

  1. BemusedbyQM

    BemusedbyQM Guest

    how would you convert an ordinary 'int' integer into a java BigDecimal? i
    have a java line that produces random java integers in the range 1 - 9 and i
    want next to convert these integers into java BigDecimals. how would i do
    this?
     
    BemusedbyQM, Nov 12, 2005
    #1
    1. Advertisements

  2. int j = ...;
    BigDecimal bd = new BigDecimal (j);
     
    Matt Humphrey, Nov 12, 2005
    #2
    1. Advertisements

  3. BemusedbyQM

    Roedy Green Guest

    Are you sure you don't want BigInteger?

    If you did then new BigInteger( String ) will do it. You must convert
    your int to String first. see
    http://mindprod.com/applets/converter.html
    for how.

    If you want BigDecimal there is new BigDecimal ( int ). I am puzzled
    why you had a problem with that one.
     
    Roedy Green, Nov 12, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.