방법1
public class NumberCheck {
public static void main(String[] args) {
System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500"));
System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500.123"));
System.out.println("## 숫자 체크 정수, 실수 : " + isStringDouble("1500T"));
}
public static boolean isStringDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
}
방법2
import org.apache.commons.lang.math.NumberUtils;
public class NumberCheck {
public static void main(String[] args) {
// Check if a String contains only digits : 문자열에 값이 digits이 포함하고 있는지 체크
System.out.println("Is Digits : " + NumberUtils.isDigits("140500.123"));
// Check if a String is a valid number : 문자열에 값이 숫자인지 체크
System.out.println("Is Number : " + NumberUtils.isNumber("140500.123"));
// Get MAX value from an array : 배열으로 부터 최대값을 추출
System.out.println("MAX : "+ NumberUtils.max(new double[] { 2.33, 10.88, 7.11 }));
}
}
--------------------------------------------
결과
--------------------------------------------
Is Digits : false
Is Number : true
MAX : 10.88
728x90
반응형
'Language > Java' 카테고리의 다른 글
| des 암복호화 (0) | 2018.01.15 |
|---|---|
| 대용량 엑셀다운로드 (0) | 2018.01.13 |
| 첨부파일 byte를 받아 [bytes, KB, MB, GB, TB, PB] 으로 변환 (0) | 2018.01.13 |
| Math.random() 취약점 대체 (0) | 2018.01.13 |
| AES128 암복호화 모듈 (0) | 2018.01.11 |