首页上一页 1 下一页尾页 1 条记录 1/1页
java小问题
发表在Java图书答疑
2013-12-25
是否精华
是
否
版块置顶:
是
否
import java.text.*;
public class DecimalFormatSimpleDemo {
// 使用实例化对象时设置格式化模式
static public void SimgleFormat(String pattern, double value) {
// 实例化DecimalFormat对象
DecimalFormat myFormat = new DecimalFormat(pattern);
String output = myFormat.format(value); // 将数字进行格式化
System.out.println(value + " " + pattern + " " + output);
}
// 使用applyPattern()方法对数字进行格式化
static public void UseApplyPatternMethodFormat(String pattern, double value) {
DecimalFormat myFormat=new DecimalFormat();//实例化DecimalFormat对象
myFormat.applyPattern(pattern); // 调用applyPatten()方法设置格式化模板
System.out
.println(value + " " + pattern + " " + myFormat.format(value));
两种方法都是实现对数字的格式化,有什么不一样吗?除了使用的方式不同
public class DecimalFormatSimpleDemo {
// 使用实例化对象时设置格式化模式
static public void SimgleFormat(String pattern, double value) {
// 实例化DecimalFormat对象
DecimalFormat myFormat = new DecimalFormat(pattern);
String output = myFormat.format(value); // 将数字进行格式化
System.out.println(value + " " + pattern + " " + output);
}
// 使用applyPattern()方法对数字进行格式化
static public void UseApplyPatternMethodFormat(String pattern, double value) {
DecimalFormat myFormat=new DecimalFormat();//实例化DecimalFormat对象
myFormat.applyPattern(pattern); // 调用applyPatten()方法设置格式化模板
System.out
.println(value + " " + pattern + " " + myFormat.format(value));
两种方法都是实现对数字的格式化,有什么不一样吗?除了使用的方式不同