1 개요[ | ]
- 자바 isNumeric()
- 자바 문자열이 숫자인지 확인
- Double 형으로 정상 파싱되면 숫자라고 본다.
Java
Copy
public class MyClass {
public static boolean isNumeric(String input) {
try {
Double.parseDouble(input);
}
catch (NumberFormatException e) {
return false;
}
return true;
}
public static void main(String args[]) {
// true
System.out.println( isNumeric("42") );
System.out.println( isNumeric("3.14") );
System.out.println( isNumeric("1e5") );
// false
System.out.println( isNumeric("A") );
}
}
Loading
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.