简体   繁体   English

Long.parseLong提供NumberFormatException

[英]Long.parseLong giving NumberFormatException

My issue is that 我的问题是

checksum = Long.parseLong("-986.9"); 

is giving NumberFormatException. 提供NumberFormatException。 Isn't this a parsible long? 这不是很长的时间吗?

A Long is not a decimal. Long不是小数。 Use Double and convert : 使用Double并转换:

Double.parseDouble("-986.9").longValue(); 

No it isn't. 不,不是。 A long is a numeric integer type, and your number has a decimal point. long是数字整数类型,您的数字有小数点。

You want a double here (ie Double.parseDouble() ). 您要在此处创建一个double Double.parseDouble()Double.parseDouble() )。

long is an integer data type, -986.9 is not an integer. long是整数数据类型,-986.9不是整数。 The below works for me. 下面为我​​工作。

long checksum = Long.parseLong("-986");
    System.out.println(checksum);
    double checksum2 = Double.parseDouble("-986.6");
    System.out.println(checksum2);

使用双Double.parseDouble(var) ,使用方法Double.parseDouble(var)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM