convert BigInteger To Double - Java java.math

Java examples for java.math:BigInteger

Description

convert BigInteger To Double

Demo Code


//package com.java2s;
import java.math.BigInteger;

public class Main {
    public static void main(String[] argv) throws Exception {
        BigInteger bigInteger = new BigInteger("1234");
        System.out.println(convertToDouble(bigInteger));
    }//w  ww.j a v a 2 s .c o  m

    public static double convertToDouble(BigInteger bigInteger) {
        double d = bigInteger.doubleValue();
        if (d == Double.POSITIVE_INFINITY) {
            return Long.MAX_VALUE;
        } else if (d == Double.NEGATIVE_INFINITY) {
            return Long.MIN_VALUE;
        }
        return bigInteger.doubleValue();
    }
}

Related Tutorials