Here's what I have now:
String text = "-9,23";
Character character = '.';
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator(character);
symbols.setGroupingSeparator(character.equals('.') ? ',' : '.');
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(symbols);
format.setParseBigDecimal(true);
ParsePosition parsePosition = new ParsePosition(0);
Object object = format.parse(text, parsePosition);
The result of this is -923 rather then some sort of java.lang.NumberFormatException which I would expect to get in this scenario. I need my code to fail hard when the incoming string based number doesn't match the predefined format standard (either US or EU) which comes from the db layer. What's the best way of doing that?