Java Convert Double to BigInteger

Tags: double BigInteger

In this Java core tutorial we learn how to convert a double value into a BigInteger value in Java programming language.

How to convert double to BigInteger in Java

In Java, with a given double value we can follow these steps to convert it into a BigInteger value.

  • Step 1: convert the double value into long value by casting it to long.
  • Step 2: instantiate a new BigInteger value from the long value from step 1 using the BigInteger.valueOf(long val) static method.

import java.math.BigInteger;

public class ConvertDoubleToBigIntegerExample {
    public static void main(String... args) {
        double doubleValue = 999999;

        // Convert Double to BigInteger
        long longValue = (long)doubleValue;
        BigInteger bigIntegerValue = BigInteger.valueOf(longValue);

        System.out.println("double value: " + doubleValue);
        System.out.println("BigInteger value: " + bigIntegerValue);
The output as below.
double value: 999999.0
BigInteger value: 999999

Happy Coding 😊

Java Convert Double to Hexadecimal String

Java Check Double is Not-a-Number (NaN)

Java Check Double is Infinite Number

Java Check Double is Finite Number