Reputation: 65
Receive all a greeting.
I need to validate that a text corresponds to a number. The project locale is es_CO. The problem I have now is that texts with a period used as a decimal separator are parsed to integer numbers, when it should be an error, since in the aforementioned location, the decimal separator is a comma.
For example:
es_CO
###.###,##
1.48
148.0
Source code:
Locale defaultLocale = new Locale("es", "CO");
NumberFormat numberFormat = NumberFormat.getNumberInstance(defaultLocale);
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
decimalFormat.applyLocalizedPattern("###.###,##");
Number number = decimalFormat.parse("1.48"); // Here I would expect an exception to be generated.
Thanks for any help you can give me.
Upvotes: 2
Views: 181