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前端其它相关文章!