由于它依赖于NumberFormat类,该类将停止在第一个无效字符处解析输入字符串,所以我认为您必须扩展NumberFormat类。
首先脸红是
public class StrictFloatNumberFormat extends NumberFormat { private void validate(in) throws ParseException{ try { new Float(in); } catch (NumberFormatException nfe) { throw new ParseException(nfe.getMessage(), 0); } public Number parse(String in) throws ParseException { validate(in); super.parse(in); } ..... //any other methods}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)