How to parse numbers more strict than what NumberFormat does in Java?

后端 未结 7 1138
醉梦人生
醉梦人生 2021-02-09 01:59

I\'m validating user input from a form.

I parse the input with NumberFormat, but it is evil and allow almost anything. Is there any way to parse number more strict?

相关标签:
7条回答
  • 2021-02-09 02:32

    Take a look at DecimalFormat that is a subclass of NumberFormat http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html

    DecimalFormat myFormatter = new DecimalFormat("###.###");

    0 讨论(0)
提交回复
热议问题