java技术博客

jsp博客
数据加载中……
FormateValue.java
/**
*通过这个程序,测试格式器的使用方法
*/
import java.text.NumberFormat;
import java.util.locale;
public class FormateValue{
public static void main(String[] args){
double x=100000.0/3;
System.out.println("the value is :"+x);
//首先以默认地区的格式器来输出
System.out.println("接下来输出的是美国地区的格式器的结果:");
NumberFormat number=NumberFormat.getNumberInstance(Locale.US);
NumberFormat number=NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat percent=NumberFormat.getPercentInstance(Locale.US);


FormatValue fm=new FormatValue();
fm.print(number,x);
fm.print(currency.x);
fm.print(percent,x);

System.out.println("接下来输出的是默认地区的格式器的结果:");
NubmerFormat nu=NumberFormat.getNumberInstance();
NubmerFormat cu=NumberFormat.getCurrencyInstance();
NubmerFormat be=NumberFormat.getPercentIntstance();
fm.print(nu,x);
fm.print(cu,x);
fm.print(pe,x);
}
public void print(NubmerFormat nu,double x){
System.out.println(nu.format(x));
}
}

posted on 2008-10-22 13:21 郭兴华 阅读(174) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: