The input string contains ,
instead of .
. Replace the ,
with .
to get rid of the exception. Ideally, the input should be 35.9
and not 35,9
.
If you are using ,
as the decimal separator, then you could use the DecimalFormatSymbols
to replace ,
as the decimal separator.
The following code demonstrates the use of DecimalFormatSymbols
class:
DecimalFormat df = new DecimalFormat("#.#");
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
dfs.setDecimalSeparator(',');
df.setDecimalFormatSymbols(dfs);
System.out.println(df.parse("35,9"));
The above code prints 35.9