Skip to content
Advertisement

is there anyway to convert from Double to BigInteger?

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.

Advertisement

Answer

If you want to store the integral part of the double into a BigInteger, then you can convert it into a BigDecimal and then into a BigInteger:

BigInteger k = BigDecimal.valueOf(doubleValue).toBigInteger();
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement