NumberFormat parse not strict enough

后端 未结 2 1592
囚心锁ツ
囚心锁ツ 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:21

    Actually, Number is just a super class for Double, so you could use Double.parseDouble(...) and then auto-unboxing should do the rest.

    0 讨论(0)
  • 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)

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