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. Advertising

  2. "BemusedbyQM" <> wrote in message
    news:nIldf.577$...
    > 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?


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

  3. BemusedbyQM

    Roedy Green Guest

    On Sat, 12 Nov 2005 13:01:07 GMT, "BemusedbyQM"
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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?
    >


    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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 12, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Krista Bailie

    Converting from integers to output

    Krista Bailie, Jul 14, 2004, in forum: Python
    Replies:
    7
    Views:
    364
    Peter Maas
    Jul 15, 2004
  2. Guest
    Replies:
    3
    Views:
    378
    Cameron Laird
    Sep 9, 2004
  3. Replies:
    26
    Views:
    1,625
    CBFalconer
    Jan 28, 2008
  4. RedGrittyBrick

    Formatting BigDecimals

    RedGrittyBrick, Feb 7, 2008, in forum: Java
    Replies:
    9
    Views:
    15,305
    RedGrittyBrick
    Feb 8, 2008
  5. Andy Luotto
    Replies:
    1
    Views:
    498
Loading...

Share This Page