Description Of BigInteger: doubleValue()
The
java.math.BigInteger.doubleValue() converts this BigInteger to a double. This conversion is similar to the narrowing primitive conversion from double to float.
If this
BigInteger has too great a magnitude to represent as a double, it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. Even when the return value is finite, this conversion can lose information about the precision of the BigInteger value.
Code Example Java BigInteger
import java.math.BigInteger;
public class BigIntegerExam {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("123");
BigInteger bi2 = new BigInteger("123456789123456789");
double bi1Double = bi1.doubleValue();
double bi2Double = bi2.doubleValue();
String str1 = "Double value of " + bi1 + " is " + bi1Double;
String str2 = "Double value of " + bi2 + " is " + bi2Double;
// print d1, d2 values
System.out.println(str1);
System.out.println(str2);
}
}