J2SE 5.0新特性(九)新的格式化方法
2011-01-23 23:35
302 查看
例如:我们在1.4版本上完成一个数字格式化输出的时候,需要:
double x = 10000.0 / 3.0;
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(4);
formatter.setMinimumIntegerDigits(6);
String s = formatter.format(x); // the string "003,333.3333"
在1.5下面只需要:
double x = 10000.0 / 3.0;
String s = String.format("%,012.4f",x);
double x = 10000.0 / 3.0;
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(4);
formatter.setMinimumIntegerDigits(6);
String s = formatter.format(x); // the string "003,333.3333"
在1.5下面只需要:
double x = 10000.0 / 3.0;
String s = String.format("%,012.4f",x);
相关文章推荐
- J2SE 5.0新特性(九)新的格式化方法
- J2SE5.0新特性之使用代理服务器
- [转]J2SE 5.0专题 之 语言特性
- J2SE 5.0专题之语言特性
- J2SE5.0中最有趣的新特性:注释(annotation)
- J2SE 5.0专题 之 语言特性
- 在 Eclipse 3.1 中体验 J2SE 5.0 的新特性: 第三部分 :范型
- [置顶] J2SE5.0新特性之使用代理服务器
- J2SE5.0新特性示例---循环语句的增强
- J2SE5.0新特性之可变长参数
- [转]J2SE 5.0新特性 之 线程
- J2SE5.0新特性之使用代理服务器
- [转帖] J2SE5.0新特性之使用代理服务器
- J2SE5.0新特性之Foreach
- J2SE 5.0新特性(四)自动装箱/拆箱
- J2SE5.0新特性之ProcessBuilder
- J2SE5.0中最有趣的新特性:注释(annotation)
- J2SE 5.0新特性 之 线程
- J2SE5.0中新特性:注释
- J2SE5.0新特性之自动装箱解箱