Best implementation for an isNumber(string) method

前端 未结 19 2541
感动是毒
感动是毒 2020-12-15 20:04

In my limited experience, I\'ve been on several projects that have had some sort of string utility class with methods to determine if a given string is a number. The idea h

19条回答
  •  一生所求
    2020-12-15 20:34

    For long numbers use this: (JAVA)

    public static boolean isNumber(String string) {
        try {
            Long.parseLong(string);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
    

提交回复
热议问题