NumberFormat

import java.text.NumberFormat;
import java.util.*;
class TestNumberFormat 
{
	public static void main(String[] args) 
	{

		double db=12343433.67779;
	    Locale[] locales={Locale.CHINA,Locale.GERMAN,Locale.US,Locale.JAPAN};
		NumberFormat[] nf=new NumberFormat[12];

		for(int i=0;i<locales.length;i++){
		  nf[i*3]=NumberFormat.getNumberInstance(locales[i]);
          nf[i*3+1]=NumberFormat.getPercentInstance(locales[i]);
		  nf[i*3+2]=NumberFormat.getCurrencyInstance(locales[i]);
		}

		for(int i=0; i<locales.length;i++){
		  switch(i){
		     case 0:
				 System.out.println("--------------------中国格式----------------------");
			     break ;
			 case 1:
			     System.out.println("--------------------德国格式----------------------");
			     break ;
			 case 2:
				 System.out.println("--------------------美国格式----------------------");
			     break ;
			 case 3:
				System.out.println("--------------------日本鬼子格式----------------------");
			     break ;
			

		  
		  }
        System.out.println("通用数值格式"+nf[i*3].format(db));
		System.out.println("通用百分比格式"+nf[i*3+1].format(db));
		System.out.println("通用货币格式"+nf[i*3+2].format(db));

		}
		
	}
}

你可能感兴趣的:(java)