aspose file tools*
The moose likes Beginning Java and the fly likes int to BigInteger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "int to BigInteger" Watch "int to BigInteger" New topic
Author

int to BigInteger

S Thanigaivel
Ranch Hand

Joined: Oct 06, 2005
Posts: 60
Can anyone let me know how to convert an 'int' to BigInteger.

---------------------------
Thanks in Advance
[ October 13, 2005: Message edited by: S Thanigaivel ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14150
    
  18

You probably already discovered that BigInteger does not have a constructor that takes an int. It does, however, have a constructor that takes a String. So all you have to do is to convert your int to a String and pass that to the constructor.
[ October 13, 2005: Message edited by: Jesper de Jong ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
The route suggested by the previous poster, int -> String -> BigInteger,
seems circuitous to this old cowpoke. Try the following BigInteger method:

For example:



There is no emoticon for what I am feeling!
Michael Kammerhofer
Greenhorn

Joined: May 30, 2012
Posts: 1
private static BigInteger xyz = BigInteger.valueOf(3);
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

And both approaches could have been found easily by spending a few minutes looking over BigInteger's javadocs.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38844
    
  23
Welcome to the Ranch Michael Kammerhofer. Why are you suggesting that field be static? Please search this forum for threads about the difference between static and non-static.
Liesbert Garcia Moreno
Greenhorn

Joined: Jan 31, 2014
Posts: 2
Jesper de Jong wrote:You probably already discovered that BigInteger does not have a constructor that takes an int. It does, however, have a constructor that takes a String. So all you have to do is to convert your int to a String and pass that to the constructor.
[ October 13, 2005: Message edited by: Jesper de Jong ]



I'm so agree with you. This'll be the way.

int x = 5;
BigInteger temp = new BigInteger(Integer.toString(x));

Ready to do anything...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38844
    
  23
Welcome to the Ranch

Did you notice that a better solution had been suggested over 8 years ago?
Liesbert Garcia Moreno
Greenhorn

Joined: Jan 31, 2014
Posts: 2
Campbell Ritchie wrote:Welcome to the Ranch

Did you notice that a better solution had been suggested over 8 years ago?


Well, users are looking for information every day, I just want to help new users. I'm sorry if I did something wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int to BigInteger