-1
我有一个.dat文件,其中包含很多巨大的数字,例如568e24 1.20536e8 1.3526e12 1.5145e11。我已经将这些数字输入为String,并存储在ArrayList中。我需要用这些数字来计算和表示太阳系中的引力体。但在java中它已经超过了Double和Int的上限。我想要在Java中使用这些数字。将大文本数字转换为BigInteger时NumberFormatException
这是我的代码,它输入这些数据并将这些数据作为字符串存储在ArrayList中。
public static void main(String[] args) throws Exception{
Scanner input = new Scanner(new File("solarsystem.dat"));
ArrayList<String[]> BodyData = new ArrayList<String[]>();
input.nextLine();
while(input.hasNextLine()){
String x = input.nextLine();
String[] x1 = x.split("[^a-zA-Z0-9().]+");
BodyData.add(x1);
}
System.out.println(BodyData.get(0)[0]);
我想使用的BigInteger通过下面的代码串改为BigIntiger:
BigInteger reallyBig = new BigInteger("1898e24");
System.out.print(reallyBig);
但输出是错误的:
Exception in thread "main" java.lang.NumberFormatException: For input string: "1898e24"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.math.BigInteger.<init>(BigInteger.java:470)
at java.math.BigInteger.<init>(BigInteger.java:606)
at tryScanner.main(tryScanner.java:18)
所以......现在..什么我应该如何使用这个庞大的数字,比如1898e24。我是否需要更改此号码(1898e24)的格式,例如1898000000000 ...?
BigDecimal是你的朋友 – Andremoniy
['BigDecimal'](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html)。 –
你应该做什么?在这里倾销你的问题之前用谷歌搜索。就那么简单。 – Paul