The java.math.BigInteger.doubleValue() converts this BigInteger to a double value. If the value return by this function is too big for a magnitude to represent as a double then it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate. There is a chance that this conversion can lose information about the precision of the BigInteger value.
public double doubleValue()
Return Value: The method returns a double value which represents double value for this BigInteger.
Input: BigInteger1=32145 Output: 32145.0 Explanation: BigInteger1.doubleValue()=32145.0. Input: BigInteger1=32145535361361525377 Output: 3.2145535E19 Explanation: BigInteger1.doubleValue()=3.2145535E19. This BigInteger is too big for a magnitude to represent as a double then it will be converted to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate.
Below programs illustrate doubleValue() method of BigInteger class:
doubleValue of 32145 : 32145.0 doubleValue of 7613721 : 7613721.0
Example 2: When returned double value is too big for a magnitude to represent as a double.
doubleValue of 32145535361361525377 : 3.2145535361361527E19 doubleValue of 7613721535372632367351 : 7.613721535372632E21
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.