Home Java Java-biginteger Java BigInteger long
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Java BigInteger long

Advertisement
We can convert the BigInteger value to the long data type and also can covert the long value to the BigInteger with the use of java.math.BigInteger class and its methods.

Java BigInteger long

     

java example program to convert the BigInteger value to long

We can  convert the BigInteger value to the long data type and also can covert the long value to the BigInteger with the use of java.math.BigInteger class and its methods.

BigInteger bi = BigInteger.valueOf(123L);

Above lines of code creates a BigInteger object with the long value "123L" and to convert the BigInteger value to the long type we can use the method longValue() of the BigInteger class.

Long result = (bigInteger1.multiply(bigInteger2)).longValue();

Above lines of code converts the bigInteger1.multiply(bigInteger2), a BigInteger value to the long. In our java example we have converted a result of two BigInteger variables value to a long variable result. Here is the full example source code of BigIntegerLong as follows:

import java.math.BigInteger;
public class BigIntegerLong
{
  public static void main(String[] args
  {
  BigInteger bigInteger1 = new BigInteger ("123456789");
  BigInteger bigInteger2 = new BigInteger ("112334");
  Long result = (bigInteger1.multiply(bigInteger2)).longValue()
  System.out.println("Result(in Long) is  ==> " + result);
  }
}

Output of the example is as follows:

C:\biginteger>javac BigIntegerLong.java

C:\biginteger>java BigIntegerLong
Result(in Long) is ==> 13868394935526

Download Example Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 4, 2008

Ask Questions?    Discuss: Java BigInteger long   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Aishwarya
August 30, 2011
comment on Biginteger

You have given a value directly into big integer. If I want to read it from the user, then how to solve this problem?
DMCA.com