【发布时间】:2013-02-13 16:19:07
【问题描述】:
我正在尝试使用 NumberFormat.getCurrencyInstance(); 将我的货币字符串解析为大十进制;
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);
}
}
有谁知道让它正常工作的好解决方案?
【问题讨论】: