Javas DecimalFormat: how to reject "invalid" input with grouped decimals?

When using the following NumberFormat: NumberFormat amountFormat = NumberFormat .getNumberInstance(I18N.getThreadLocale()); amountFormat.setMaximumFractionDigits(2); amountFormat.setMinimumFractionDigits(2); I get the following results when parsing via System.out.println(amountFormat.parse(value)); * 10,50 => 1050 * 10,5 => 105 * 0,25 => 25 I know that in Locale.ENGLISH the "," is the group separator. But I don't think that the above results make sense. And our customers get weird about this formatting. How can I disable this grouping? I would like to have the following results: * 10,50 => ParseException * 10,5 => ParseException * 0,25 => ParseException Is there a standard way to do this? Or do I have to program my own NumberFormat?
Why not just search for the comma before passing it to the parse value? If you want to get a Format Exception you could replace the comma with another invalid character.

以上就是Javas DecimalFormat: how to reject "invalid" input with grouped decimals?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准