Java BigInteger longValue() method

The longValue() method of Java BigInteger class is used to convert this BigInteger to a long.This conversion is similar to the narrowing primitive conversion from long to int.

Narrowing Primitive Conversion:

According to The Java Language Specification, it is defined as ifthisBigInteger has too great magnitude to represent as along, it will return only the lower order 64 bits.

Syntax:

Returns:

This method returns this BigInteger converted to a long.

Note:
  • This method is specified by longValue in class Number.
  • When the return value is finite, this conversion can lose information about the precision of the BigInteger value and return a result with the opposite sign.

Example

Test it Now

Output:

Result of longValueoperation on 123 is   123
Result of longValueoperation on -123 is   -123
Result of longValue operationon12345678901234567890 is-6101065172474983726
Result of longValueoperation on   -12345678901234567890 is
6101065172474983726

Next TopicJava BigInteger




Latest Courses