int/double/String 형태의 데이터를 받아서 해당 데이터의 숫자형태를 000,000,000 식으로 변경하는
소스 입니다.
double num = 29600000;
DecimalFormat df = new DecimalFormat("#,##0.00");
System.out.println(df.format(num));
"#,##0.00" 경우 소숫점 2자리 까지 출력 되게 됩니다.
DecimalFormat df = new DecimalFormat("#,###");
System.out.println(df.format(num));
이렇게 하는 경우에는 소숫점 숫자를 반올림 하게 됩니다.
int i = 1000000;
String str = String.format("%,d", i);
float f = 234000.987654;
String str = String.format("%,.3", f);
이렇게 처리 하는 방법도 있습니다.
String 형태의 경우 replaceAll을 이용해서
String str = "2231342112134.6";
str = str.replaceAll("(?<=[0-9])(?=([0-9][0-9][0-9])+(?![0-9]))", ",");
System.out.println(str);
수정 하는 방법도 있습니다.
반응형
'JAVA' 카테고리의 다른 글
java동작 환경 메모리 상태 (0) | 2015.07.03 |
---|---|
url결과를 이미지 혹은 pdf로 생성하는 프로그램 (0) | 2015.07.03 |
apache configuration을 이용한 XML파일 작업 (0) | 2015.05.15 |
URLConnection 을 이용해서 url결과를 가지고 오는 메소드 (0) | 2015.04.14 |
RSS XML 정보를 가지고 오는 소스 (0) | 2015.04.14 |