编程语言
首页 > 编程语言> > Exception in thread "main" java.lang.NumberFormatException: For input string: "1.6262

Exception in thread "main" java.lang.NumberFormatException: For input string: "1.6262

作者:互联网

问题还原:

public static void main(String[] args) {
String startTime ="1.626290463E12";
System.out.println("begin================"+Long.parseLong(startTime));
}

报错信息:

Exception in thread "main" java.lang.NumberFormatException: For input string: "1.626290463E12"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at basis.xz.stringformat.main(stringformat.java:34)

 

解决:

public static void main(String[] args) {

String startTime ="1.626290463E12";
//long类型十进制还原
BigDecimal v = new BigDecimal(startTime).setScale(0,BigDecimal.ROUND_HALF_UP);
System.out.println(Long.parseLong(v));
}

标签:lang,Exception,java,parseLong,E12,Long,main
来源: https://www.cnblogs.com/lwdwl/p/15040074.html