is there anyway to convert from Double to BigInteger?

情到浓时终转凉″ 提交于 2019-11-29 09:24:37

BigInteger is made for holding arbitrary precision integer numbers, not decimals. You can use the BigDecimal class to hold a double.

BigDecimal k = BigDecimal.valueOf(doublevalue);

In general, you cannot type cast a Java primitive into another class. The exceptions that I know about are the classes extending Number, such as the Long and Integer wrapper classes, which allow you to cast an int value into an Integer, and so on.

bb94

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

BigInteger k = BigDecimal.valueOf(doublevalue).toBigInteger();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!