sitelink1  
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  
http://blog.naver.com/vscapital/120036411418
·미리보기 | 소스복사·
  1. /*  
  2.  * FormatImpl.java  
  3.  *  
  4.  * Created on 2007년 4월 3일 (화), 오후 12:46  
  5.  *  
  6.  * To change this template, choose Tools | Template Manager  
  7.  * and open the template in the editor.  
  8.  */  
  9.   
  10. package test;   
  11.   
  12. /**  
  13.  *  
  14.  * @author Administrator  
  15.  */  
  16. import java.text.DecimalFormat;   
  17. import java.text.NumberFormat;   
  18. import java.util.Locale;   
  19. import java.text.DecimalFormatSymbols;   
  20. import java.util.Currency;   
  21. import java.text.ParsePosition;   
  22.   
  23. public class FormatImpl {   
  24.        
  25.     /** Creates a new instance of FormatImpl */  
  26.     public FormatImpl() {   
  27.     }   
  28.     public static void main(String []  args) {   
  29.         System.out.println("**************************달러를 $로 표기******************************");   
  30.         DecimalFormatSymbols symbol = new DecimalFormatSymbols();   
  31.         symbol.setCurrencySymbol("$");   
  32.         DecimalFormat df = new DecimalFormat("###,##0.##",symbol);   
  33.         System.out.println(symbol.getCurrencySymbol() + df.format(123456789123.77));   
  34.         System.out.println("**************************달러를 $로 표기끝****************************");   
  35.            
  36.         System.out.println("**************************달러를 USD로 표기****************************");   
  37.         DecimalFormatSymbols symbol1 = new DecimalFormatSymbols(Locale.US);   
  38.         DecimalFormat df1 = new DecimalFormat("###,##0.##",symbol1);   
  39.         System.out.println(symbol1.getCurrency() + df1.format(123456789123.77));   
  40.         System.out.println("**************************달러를 USD로 표기끝**************************");   
  41.            
  42.         System.out.println("**************************원화를 KRW로 표기****************************");   
  43.         //내컴퓨터는 default로 Locale이 KOREA로 되어있기때문에...   
  44.         //우리나라에서 쓰면 대부분의 Locale이 KOREA일꺼임..   
  45.         DecimalFormatSymbols symbol2 = new DecimalFormatSymbols();   
  46.         DecimalFormat df2 = new DecimalFormat("###,##0.##",symbol2);   
  47.         // 앞에서 11자리 건너뛰고 표기   
  48.         Number num = df2.parse("123456789123.77"new ParsePosition(11));   
  49.         System.out.println(symbol2.getCurrency() + df2.format(num.doubleValue()));   
  50.         System.out.println("**************************원화를 KRW로 표기끝**************************");   
  51.            
  52.         System.out.println("**************************소수점 이하 자리수 정하기*********************");   
  53.         DecimalFormatSymbols symbol3 = new DecimalFormatSymbols();   
  54.         DecimalFormat df3 = new DecimalFormat("###,##0.##",symbol3);   
  55.         //df3.setMaximumFractionDigits(5);   
  56.         df3.setMinimumFractionDigits(3);   
  57.         System.out.println(symbol3.getCurrency() + df3.format(123456789123.00000));   
  58.         System.out.println("**************************소수점 이하 자리수 정하기끝*******************");   
  59.            
  60.         System.out.println("**************************정수만 가져오되 0자리수 부터 정해진만큼 가져오기*********************");   
  61.         DecimalFormatSymbols symbol4 = new DecimalFormatSymbols();   
  62.         DecimalFormat df4 = new DecimalFormat("###,##0.##",symbol4);   
  63.         df4.setMaximumIntegerDigits(10);   
  64.         //df4.setMaximumIntegerDigits(7);   
  65.         System.out.println(symbol4.getCurrency() + df4.format(123456789123.00000));   
  66.         System.out.println("**************************정수만 가져오되 0자리수 부터 정해진만큼 가져오기*********************");   
  67.     }   
  68.   
  69. System.out.println("**************************앞에서부터 0 채우기*********************");   
  70.         DecimalFormatSymbols symbol5 = new DecimalFormatSymbols();   
  71.         DecimalFormat df5 = new DecimalFormat("00000",symbol5);   
  72.         System.out.println(df5.format(1));   
  73.         System.out.println("**************************앞에서부터 0 채우기*********************");   
  74. }  

번호 제목 글쓴이 날짜 조회 수
143 숫자 에 대응 되는 패턴의 형식화 #1 황제낙엽 2008.07.08 359
142 숫자를 통화 표기 형태로 변환하기 황제낙엽 2008.07.08 347
» NumberFormat, DecimalFormat 사용예 황제낙엽 2008.07.08 402
140 파일의 내용을 읽어 String 객체로 만드는 함수 황제낙엽 2008.06.17 296
139 UTF형태 파일에서 BOM 제거하기 황제낙엽 2008.06.16 2243
138 불러온 txt파일의 Encoding을 알 수는 방법좀 가르쳐 주세요~ 황제낙엽 2008.06.16 388
137 FileFilter, FilenameFilter 클래스를 이용한 파일 또는 디렉토리 리스트 추출하기 황제낙엽 2008.06.16 493
136 정규식 사용예제 [2] 황제낙엽 2008.06.11 384
135 정규식 사용예제 [1] 황제낙엽 2008.06.11 436
134 StringBuffer vs String 황제낙엽 2008.06.10 314
133 작지만 강력한 HTML 파서, HtmlCleaner, html parser 황제낙엽 2008.06.10 398
132 Jericho HTML Parser 황제낙엽 2008.06.10 556
131 JTidy(HTML Parser) How to 황제낙엽 2008.06.10 437
130 NekoHTML 샘플 예제 황제낙엽 2008.06.09 427
129 YGHTML Parser 0.1.1 샘플 예제 황제낙엽 2008.06.09 358
128 HTML Paser 의 종류 황제낙엽 2008.06.09 710
127 File 생성시 encoding 지정하기 (Unicode/utf-8 file 읽고 쓰기) 황제낙엽 2008.05.22 756
126 java String.replaceAll (String regex, String replacement) 쓸떄 조심할 것 황제낙엽 2008.05.22 424
125 java String.replaceAll 잘쓰기 황제낙엽 2008.05.22 429
124 간단한 DBConnection 프로그램 (JDBC) file 황제낙엽 2008.05.15 456