我正在尝试使用 NumberFormat.getCurrencyInstance(); 将我的货币字符串解析为 bigdecimal;
The following scenario
$1,000.01 Pass
1000.01 Pass
1,000.01 Fail -> This needs to be parsed to 1000.01 in order to pass.
abc Fail -> correct behavior.
我的方法
public BigDecimal parseClient(Field field, String clientValue, String message) throws ValidationException {
if (clientValue == null) {
return null;
}
NumberFormat nf = NumberFormat.getCurrencyInstance();
try {
return new BigDecimal(nf.parse(clientValue).toString());
} catch (ParseException ex) {
throw new ValidationException(message);
}
}
有人知道一个很好的解决方案来让它正常工作吗?