is there anyway to convert from Double to BigInteger?

Krack picture Krack · Jul 31, 2013 · Viewed 34.2k times · Source

Is there anyway to convert from double value to BigInteger?

double doubleValue = 64654679846513164.2;
BigInteger bigInteger = (BigInteger) doubleValue;

I try to cast it but it didn't work.

Answer

bb94 picture bb94 · Jan 18, 2014

You can convert the double into a BigDecimal and then into a BigInteger:

BigInteger k = BigDecimal.valueOf(doublevalue).toBigInteger();