Reputation: 251
My issue is that
checksum = Long.parseLong("-986.9");
is giving NumberFormatException. Isn't this a parsible long?
Upvotes: 0
Views: 712
Reputation: 3103
long is an integer data type, -986.9 is not an integer. The below works for me.
long checksum = Long.parseLong("-986");
System.out.println(checksum);
double checksum2 = Double.parseDouble("-986.6");
System.out.println(checksum2);
Upvotes: 0
Reputation: 121712
No it isn't. A long
is a numeric integer type, and your number has a decimal point.
You want a double
here (ie Double.parseDouble()
).
Upvotes: 0
Reputation: 15070
A Long
is not a decimal. Use Double
and convert :
Double.parseDouble("-986.9").longValue();
Upvotes: 5