Hello, I have the following code to parse a String variable called str.
NumberFormat formatter = NumberFormat.getInstance();
Number number = formatter.parse(str);
I want to catch the Exception thrown when str is not a number just to validate it. The problem I have is that it does't always throws the ParseException expected. When the String str starts with a number but then are characters it seems to get a the first characters of the String and parse them as a number.
For example:
- if str="a10" then is thrown a ParseException
- if str="10a" then no exception thrown and number=10
I cannot use Double.parseDouble(str) because str can have commas and points like 1,000.98 and this format is not understood by this method.
Why is this happening? Can I validate it in any other way? Thanks