liuqiang5151

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 23 Stories :: 1 Comments :: 0 Trackbacks
import java.text.NumberFormat;
class A{
static String percent(double p1,double p2){
  String str;
  
double p3=p1/p2;
  NumberFormat nf
=NumberFormat.getPercentInstance();
  nf.setMinimumFractionDigits(
2);
  str
=nf.format(p3);
  
return str;
}

}

public class Test{
public static void main(String args[]){
  System.out.println(
"test1: "+A.percent(1,3));
  System.out.println(
"test2: "+A.percent(1,4));
}

}

posted on 2007-09-07 19:53 刘强 阅读(1904) 评论(0)  编辑  收藏 所属分类: java