Most elegant isNumeric() solution for java

前端 未结 7 899
囚心锁ツ
囚心锁ツ 2021-02-13 01:31

I\'m porting a small snippet of PHP code to java right now, and I was relying on the function is_numeric($x) to determine if $x is a number or not. Th

相关标签:
7条回答
  • 2021-02-13 02:20

    Note that the PHP isNumeric() function will correctly determine that hex and scientific notation are numbers, which the regex approach you link to will not.

    One option, especially if you are already using Apache Commons libraries, is to use NumberUtils.isNumber(), from Commons-Lang. It will handle the same cases that the PHP function will handle.

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