I'm reading some .csv file that contain string that rapresents decimal number. My trouble is that many times I'm reciving file write with different locale. For example:
- The value of the column price of file1.csv is 129,13 (, is a decimal separator)
- The value of the column price of file1.csv is 129.13 (. is a decimal separator)
Now I'm trying to read the value in this way:
DecimalFormatSymbols dfs = new DecimalFormatSymbols(new Locale(en,US));
DecimalFormat df= new DecimalFormat();
df.setDecimalFormatSymbols(dfs);
df.setParseBigDecimal(true);
bigDecimal = (BigDecimal) df.parse(value);
Using this snippet code the first value become 12913 (not correct), while the second one become 129.13 (correct). Now I would want that if I using en_US local and the file contains values that use , like decimal separator, I have to throw an exception.
How can I do this?
From the Java Tutorials:
You need to set the DeciamlFormat pattern to pull it all together.