포맷된 객체 만들기 예

1. 숫자를 화폐 문자열로 포맷하기
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class FormatNumber {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);//  
        System.out.println(" :");
        double number = scan.nextDouble();//  
        System.out.println(" Locale , :");
        //  
        NumberFormat format = NumberFormat.getCurrencyInstance(Locale.CHINA);
        //  
        System.out.println("Locale.CHINA:" + format.format(number));
        format = NumberFormat.getCurrencyInstance(Locale.US);
        System.out.println("Locale.US:" + format.format(number));
        format = NumberFormat.getCurrencyInstance(Locale.ENGLISH);
        System.out.println("Locale.ENGLISH:" + format.format(number));
        format = NumberFormat.getCurrencyInstance(Locale.TAIWAN);
        System.out.println("Locale.TAIWAN:" + format.format(number));
    }
}

2. 서식 적용 날짜
package com.lixiyu;
import java.util.Date;
public class Year {
public static void main(String[] args){
    Date date=new Date();
    String year=String.format("%tY",date);
    String month=String.format("%tB",date);
    String day=String.format("%td",date);
    System.out.println(" :"+year+" ");
    System.out.println(" :"+month);
    System.out.println(" :"+day+" ");
}
}

좋은 웹페이지 즐겨찾기