converting integers to BigDecimals

B

BemusedbyQM

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

Matt Humphrey

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

int j = ...;
BigDecimal bd = new BigDecimal (j);
 
R

Roedy Green

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top