NumberFormat parse not strict enough

后端 未结 2 1613
囚心锁ツ
囚心锁ツ 2021-01-18 01:27

I have a JFormattedTextField with a NumberFormat with Locale.US. So the decimal separator is the point and the grouping separator is the comma.

2条回答
  •  轮回少年
    2021-01-18 02:25

    I would suggest you to use regex and use the match fucntion like this:

    matches("\\d+([.,])?")
    

    Also if you will use Integer.parseInt(String) will throw an exception if it will be parsed or you can use Double.parseDouble(value)

提交回复
热议问题