利用java类Numberformat格式化数据

类别:Java 点击:0 评论:0 推荐:

//use Number Format 格式化数据
import java.text.*;
import java.util.*;

public class IntegerSample {
 public static void  main(String args[]) {
  int amount = 54321;
  NumberFormat myformat = NumberFormat.getInstance();//system format
  System.out.println(myformat.format(amount));
  NumberFormat usformat = NumberFormat.getIntegerInstance(Locale.US);//use format
  System.out.println(usformat.format(amount));
  NumberFormat germanformat = NumberFormat.getInstance(Locale.CHINA);//china  format
  System.out.println(germanformat.format(amount));
  NumberFormat jaformat = NumberFormat.getInstance(Locale.JAPAN);//japan format
  System.out.println(jaformat.format(amount));
 }

}

 

//---------------------------------//

运行结果:

F:\2004-04-12>java IntegerSample
54,321
54,321
54,321
54,321

 

本文地址:http://com.8s8s.com/it/it16605.htm