随笔-61  评论-13  文章-19  trackbacks-0
  问题一:
  有int型数字如下,123,1234,12345,123456,1234567,12345678,123456789
  求一个方法,输出123 1,234 12,345 123,456 1,234,567 12,345,678 123,456,789

  处理:
  public void testPrint(int num) {
    DecimalFormat format = new DecimalFormat("#,###");
    System.out.println(format.format(num));
  }


 问题二、
double类型如何正确的转换为字符串类型

处理:
 double d = 0.001;
    DecimalFormat df1 = new DecimalFormat("#.####");
    String result = df1.format(d);
    System.out.println(result);
posted on 2006-03-22 15:53 xnabx 阅读(885) 评论(2)  编辑  收藏 所属分类: Java

评论:
# re: DecimalFormat 2006-09-25 15:55 | saidas
正在找关于这个DecimalFormat类的一些解释,这篇文章正好有用,谢谢了!
我是baidu找到这里的。  回复  更多评论
  
# re: DecimalFormat 2008-08-06 13:14 | 漫步金星
有點淺  回复  更多评论
  

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


网站导航: