0

I cant figure it out

double d = Double.valueOf(str);
double d2 = Double.parseDouble(str);

both methods produce the following exception:

java.lang.NumberFormatException: Invalid double: "‎-73.04"

However, the following hardcoded value works just fine:

double d = Double.valueOf("-73.04");

7
  • So the problem is in the content of the string. The dot and/or minus characters are maybe not the same as in your hardcoded example. Commented Nov 17, 2015 at 23:07
  • Have you tried to trim your string passed to both methods? It might contains additional characters like whitespace or line return that these methods don't understand. Commented Nov 17, 2015 at 23:08
  • i replaced . & - with mine. trim also not help Commented Nov 17, 2015 at 23:10
  • im reading data from xls file, some of data is good, but some crashing from some reason Commented Nov 17, 2015 at 23:12
  • does your string itself contains double quotes or does it contain leading or trailing spaces ? Commented Nov 17, 2015 at 23:12

1 Answer 1

2

After copying the number from the title of this question and pasting into IntelliJ between double-quotes, it became clear what the problem is:

double d = Double.parseDouble("\u200E-73.04");

Exception in thread "main" java.lang.NumberFormatException: For input string: "?-73.04"

Copying it from your hard-coded -73.04 does not have this behavior.

You have a "left-to-right mark" Unicode character in your string somehow. You must eliminate that extraneous Unicode character from your string before parsing it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.