I want to parse a string to decimal using this method
try {
Double.parseDouble(str);
} catch (Exception exception) {
exception.printStackTrace();
}
It throws exception if I put any letter in EditText or a number followed by a letter(so far so good),but when I enter a number followed by letter d or f(example 2.1or 2.1f) it doesen't throw exception.The method treats 2.1d string or 2.1f string as 2.1float or 2.1double and return the double as 2.1d or 2.1f and the program crashes. I also tried to parse the string using :
NumberFormat.getInstance().parse(str);
Double.valueOf(str);
Double doubleObject = new Double(str);
double number = doubleObject.doubleValue();
StringUtils.isNumeric(str);
and the result was the same.
In the end I did it using if(str.contains(d)||str.contains(f))throw new Exception(...)
Is there another method or another way to do this without using if.