The Wayback Machine - https://web.archive.org/web/20241126225513/https://www.geeksforgeeks.org/biginteger-doublevalue-method-in-java/
Open In App

BigInteger doubleValue() Method in Java

Last Updated : 04 Dec, 2018
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Syntax:

public double doubleValue()

Return Value: The method returns a double value which represents double value for this BigInteger.

Examples:

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:

Example 1:




// Java program to demonstrate doubleValue() method of BigInteger
  
import java.math.BigInteger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Creating 2 BigInteger objects
        BigInteger b1, b2;
  
        b1 = new BigInteger("32145");
        b2 = new BigInteger("7613721");
  
        // apply doubleValue() method
        double doubleValueOfb1 = b1.doubleValue();
        double doubleValueOfb2 = b2.doubleValue();
  
        // print doubleValue
        System.out.println("doubleValue of " + b1 + " : " + doubleValueOfb1);
        System.out.println("doubleValue of " + b2 + " : " + doubleValueOfb2);
    }
}


Output:

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.




// Java program to demonstrate doubleValue() method of BigInteger
  
import java.math.BigInteger;
  
public class GFG {
  
    public static void main(String[] args)
    {
  
        // Creating 2 BigInteger objects
        BigInteger b1, b2;
  
        b1 = new BigInteger("32145535361361525377");
        b2 = new BigInteger("7613721535372632367351");
  
        // apply doubleValue() method
        double doubleValueOfb1 = b1.doubleValue();
        double doubleValueOfb2 = b2.doubleValue();
  
        // print doubleValue
        System.out.println("doubleValue of " + b1 + " : " + doubleValueOfb1);
        System.out.println("doubleValue of " + b2 + " : " + doubleValueOfb2);
    }
}


Output:

doubleValue of 32145535361361525377 : 3.2145535361361527E19
doubleValue of 7613721535372632367351 : 7.613721535372632E21

Reference: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#doubleValue()



Similar Reads

Integer doubleValue() Method in Java
The doubleValue() method of Integer class of java.lang package is used to convert the value of the given Integer to a Double type after a widening primitive conversion and returns it. Syntax: public double doubleValue() Parameters: The method does not take any parameter. Return Value: This method returns a numeric value represented by this object a
1 min read
Number.doubleValue() method in java with examples
The java.lang.Number.doubleValue() is an inbuilt method in java that returns the value of the specified number casted as a double data type. This may involve rounding or truncation. Syntax: public abstract double doubleValue() Parameters: This method does not accepts any parameter. Return value: This method returns the numeric value represented by
1 min read
BigDecimal doubleValue() Method in Java
The java.math.BigDecimal.doubleValue() is an in-built function which converts the BigDecimal object to a double. This function converts the BigDecimal to Double.NEGATIVE_INFINITY or Double.POSITIVE_INFINITY as appropriate or according to the passed object, if its magnitude is too big to be represented as a double. Note: The information about the de
2 min read
Byte doubleValue() method in Java with examples
The doubleValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as double. Syntax ByteObject.doubleValue() Return type: It returns the value of ByteObject as double. Below is the implementation of doubleValue() method in Java: Example 1: // Java code to demonstrate // Byte doubleValue() meth
2 min read
Double doubleValue() method in Java with examples
The doubleValue() method of Double class is a built in method to return the value specified by the calling object as double after type casting. Syntax: DoubleObject.doubleValue() Return Value: It return the value of DoubleObject as double. Below programs illustrate doubleValue() method in Java: Program 1: Java Code // Java code to demonstrate // Do
2 min read
Short doubleValue() method in Java with Examples
The java.lang.Short.doubleValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a double. Syntax: public double doubleValue() Return type: It return the value of ShortObject as double. Below is the implementation of doubleValue() method in Java: Example 1: // Java code to demonstrate //
2 min read
LongAdder doubleValue() method in Java with Examples
LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.doubleValue() is an inbuilt method in java that returns the sum as a double value. When the object of the class is created its initial value is zero. Syntax: public double doubleValue() Parameters: The function does not accepts any parameter. Return value: T
2 min read
DoubleAdder doubleValue() method in Java with Examples
The java.DoubleAdder.doubleValue() is an inbuilt method in java that is equivalent to the method sum(), that is it returns current sum value. When the object of the class is created its initial value is zero. Syntax: public double doubleValue() Parameters: The method does not accepts any parameter. Return value: This method returns the current sum.
1 min read
LongAccumulator doubleValue() method in Java with Examples
The java.LongAccumulator.doubleValue() is an inbuilt method in java that returns the current value as a double after a widening primitive conversion. Syntax: public double doubleValue() Parameters: This method does not accepts any parameter. Return Value: This method returns the current value as a double after a widening primitive conversion. Below
2 min read
AtomicInteger doubleValue() method in Java with examples
The java.util.concurrent.atomic.AtomicInteger.doubleValue() is an inbuilt method in java which returns the current value of the AtomicInteger as a Double data-type after performing primitive conversion. Syntax: public double doubleValue() Parameters: The function does not accepts any parameter. Return value: The function returns the numeric value r
1 min read
AtomicLong doubleValue() method in Java with examples
The Java.util.concurrent.atomic.AtomicLong.doubleValue() is an inbuilt method in java which returns the current value of the AtomicLong as a Double data-type after performing primitive conversion. Syntax: public double doubleValue() Parameters: The function does not accepts any parameter. Return value: The function returns the numeric value represe
1 min read
DoubleAccumulator doubleValue() method in Java with Examples
The Java.DoubleAccumulator.doubleValue() is an inbuilt method in java that is equivalent to get() method, it means it only returns the current value and does not takes any parameter. The return type of this method is int. Syntax: public double doubleValue() Parameters: The function does not accepts any parameter. Return value: The method returns th
2 min read
Float doubleValue() method in Java with examples
The doubleValue() method of Float class is a built in method to return the value specified by the calling object as double after type casting. Syntax: FloatObject.doubleValue() Return Value: It return the double value of this Float object. Below programs illustrate doubleValue() method in Java: Program 1: Java Code // Java code to demonstrate // Fl
2 min read
Java.math.BigInteger.modInverse() method in Java
Prerequisite : BigInteger Basics The modInverse() method returns modular multiplicative inverse of this, mod m. This method throws an ArithmeticException if m <= 0 or this has no multiplicative inverse mod m (i.e., gcd(this, m) != 1). Syntax: public BigInteger modInverse(BigInteger m) Parameters: m - the modulus. Return Value: This method return
2 min read
Java.math.BigInteger.probablePrime() method in Java
Prerequisite : BigInteger Basics The probablePrime() method will return a Biginteger of bitLength bits which is prime. bitLength is provided as parameter to method probablePrime() and method will return a prime BigInteger of bitLength bits. The probability that a BigInteger returned by this method is composite and does not exceed 2^-100. Syntax: pu
2 min read
BigInteger signum() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.signum() method helps us to identify whether a BigInteger is positive or zero or negative. It returns one of the following values depending on the following conditions: returns -1 when number is negativereturns 0 when number is zeroreturns +1 when number is positive Syntax: public int signum
2 min read
BigInteger shiftRight() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.shiftRight(int n) method returns a BigInteger whose value is (this >> n). The shift distance, n, may be negative, in which case this method performs a left shift. The shiftRight() method will move each digit in a number's binary representation right by n times and the last bit in the d
2 min read
Java 8 | BigInteger divideAndRemainder() method with Examples
java.math.BigInteger.divideAndRemainder(BigInteger val) was introduced in Java 8. This method returns an array of two BigInteger after applying division operation between the BigInteger calling this method and the BigInteger passed as a parameter to the other method. Here, First BigInteger of the array represents a result of the division (this / va
3 min read
BigInteger abs() Method in Java
prerequisite : BigInteger Basics The java.math.BigInteger.abs() method returns absolute value of a BigInteger. By using this method one can find absolute value of any large size of numerical data stored as BigInteger. Syntax: public BigInteger abs() Parameters: The method does not take any parameters. Return Value: The method returns the absolute v
1 min read
BigInteger modPow() Method in Java
Prerequisite: BigInteger BasicsThe Java.math.BigInteger.modPow() method returns a BigInteger whose value is (thisexponent mod m ). If exponent == 1, the returned value is (this mod m) and if exponent < 0, the returned value is the modular multiplicative inverse of (this-exponent). The method throws an ArithmeticException if m <= 0. Syntax: pu
2 min read
BigInteger or() method in Java
Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used with the function is negative. OR() method of BigInte
2 min read
BigInteger xor() Method in Java
Prerequisite: BigInteger Basics The xor(BigInteger val) method returns bitwise-XOR of two bigIntegers. This method returns a negative BigInteger if and only if exactly one of the current bigInteger and the bigInteger passed in parameter id negative. The xor() method of BigInteger class apply bitwise-XOR operation upon the current BigInteger and Big
2 min read
BigInteger and() Method in Java
The java.math.BigInteger.and(BigInteger val) method returns a BigInteger whose value is bitwise-AND of two BigIntegers. This method returns a negative number if both of the BigIntegers are negative. The and() method applies bitwise-AND operation upon the current bigInteger and bigInteger passed as parameter.Syntax: public BigInteger and(BigInteger
2 min read
BigInteger not() Method in Java
The java.math.BigInteger.not() method is used to find the bitwise-NOT of a BigInteger. This method returns a negative value if and only if this BigInteger is non-negative. The BigInteger.not() method apply bitwise Not operation upon the current bigInteger. Syntax: public BigInteger not() Parameters: The method does not take any parameters. Return V
1 min read
BigInteger andNot() Method in Java
The java.math.BigInteger.andNot(BigInteger val) method returns a BigInteger whose value is (this & ~val) where this to the current BigInteger with which the function is being used and val is the bigInteger passed to the function as a parameter. This method, which is equivalent to and(val.not()), is provided as a convenience for masking operatio
2 min read
BigInteger bitCount() Method in Java
Prerequisite: BigInteger Basics The java.math.BigInteger.bitCount() method returns number of bits in the two's complement representation of this BigInteger that differ from its sign bit. This method is useful when implementing bit-vector style sets atop BigIntegers.Syntax: public int bitCount() Parameters: The method does not take any parameters.Re
1 min read
BigInteger bitLength() Method in Java
The java.math.BigInteger.bitLength() method returns the number of bits in the minimal two's-complement representation of this BigInteger, excluding a sign bit. For positive BigIntegers, this is equivalent to the number of bits in the ordinary binary representation. The bitLength method Computes (ceil(log2(this < 0 ? -this : this+1))).Syntax: pub
2 min read
BigInteger clearBit() Method in Java
Prerequisite: BigInteger BasicsThe clearBit() method returns a BigInteger which is used to clear a particular bit position in a BigInteger. The bit at index n of binary representation of BigInteger will be cleared means converted to zero. Mathematically we can say that it is used to calculate this & ~(1<<n).Syntax: public BigInteger clear
2 min read
BigInteger flipBit() Method in Java
Prerequisite: BigInteger Basics The java.math.BigInteger.flipBit(index) method returns a BigInteger which is used to flip a particular bit position in a BigInteger. This method Computes (bigInteger ^ (1<<n)). The bit at index n of binary representation of the bigInteger will be flipped. That is, if the bit position is 0 it will be converted t
2 min read
BigInteger negate() Method in Java
Prerequisite: BigInteger Basics The java.math.BigInteger.negate() method returns a BigInteger whose value is (- this). negate() method will change the signed bit of BigInteger. Syntax: public BigInteger negate() Parameters: The method does not accept any parameter. Return Value: The method returns the operation of (- this). Examples: Input: value =
1 min read
three90RightbarBannerImg