I have a string that I'm trying to parse into a BigDecimal. I'm using the following regex to strip all non currency symbols with the exception of -,.()$. Once it has been stripped, I'm then trying to create a BigDecimal with the remaining value. The problem begins when a negative value comes across in brackets. Does anybody have any suggestions on how to repair this instance?
(1000.00) fails
I'm assuming I must somehow convert the brackets to a negative sign.
code sample.
public BigDecimal parseClient(Field field, String clientValue, String message) throws ValidationException {
if (clientValue == null) {
return null;
}
try {
clientValue = clientValue.replaceAll( "[^\\d\\-\\.\\(\\)]", "" );
return new BigDecimal(clientValue.toString());
} catch (NumberFormatException ex) {
throw new ValidationException(message);
}
}