Java教程

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));
}
这篇关于Exception in thread "main" java.lang.NumberFormatException: For input string: "1.6262的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!