I have problem about convertion from string to long value. Example :
String a = "4.0";
Long l= Long.parseLong(a);
When I execute, get exception:
Exception in thread "main" java.lang.NumberFormatException: For input string: "4.0"
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 com.tests.Test2.main(Test2.java:69)
Any idea? Thanks!
4.0 isn't a long value It's a double, Try Double.parseDouble(a)
You are attempting to covert a string with an unsupported character, ., into a Long. This is not supported by https://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#parseLong(java.lang.String). Try Long l = Double.valueOf(a).longValue();: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#valueOf(java.lang.String).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With