1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| AbstractFormatter nf = new AbstractFormatter() {
private final NumberFormat NF = NumberFormat.getIntegerInstance();
@Override
public Object stringToValue(String source) throws ParseException {
ParsePosition pp = new ParsePosition(0);
Number number = NumberFormat.getIntegerInstance().parse(source, pp);
if (pp.getIndex()!=source.length()) {
throw new ParseException("For input string : '" + source + "'", pp.getIndex());
}
return number;
}
@Override
public String valueToString(Object value) throws ParseException {
return NF.format(value);
}
}; |