我将一个BigInteger转换为float与int,BigInteger超过了它们的范围,应该会丢失数据:
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger bi = new BigInteger("99999").pow(99);
float f = bi.floatValue();
int i = bi.intValue();
System.out.println(f); //Infinity!
System.out.println(i); //-654040097!
}
}
为什么会这样子啊?谁给讲解一下
再求点BigInteger的习题
没有为什么啊,为啥要有这个BigInteger这个东西,因此这个可以表示的数值范围更大,普通的int能表示的数值范围更小,你把大的数值转为小的,肯定会丢失啊,int都表示不了那么大数值。
习题的话,这里有些:https://www.cnblogs.com/ygh1229/p/5800001.html
https://blog.csdn.net/laaahu/article/details/102608571
望采纳!!!!!!!!!!!!
因为java中int只有32位,你想输出new BigInteger("99999").pow(99);这么大的数,只能用String了。
System.out.println(bi);