已有101人关注
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));

两种方法都是实现对数字的格式化,有什么不一样吗?除了使用的方式不同
分享到:
精彩评论 1
无语_mrkj
学分:3155 LV11
2013-12-25
沙发
这两种方法都可以实现对数字的格式化,使用哪个都可以。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照