int a = 12345678;
©Å_ùªí(þeâwww.nfhot.comh$»*b) //格式为sring输出
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("asdfadsf{0}adsfasdf",a);
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = "asdfadsf"+a.ToString()+"adsfasdf";
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("asdfadsf{0:C}adsfasdf",a);//asdfadsf¥1,234.00adsfasdf
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = "asdfadsf"+a.ToString("C")+"adsfasdf";//asdfadsf¥1,234.00adsfasdf
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b) double b = 1234.12543;
©Å_ùªí(þeâwww.nfhot.comh$»*b) a = 12345678;
©Å_ùªí(þeâwww.nfhot.comh$»*b) //格式为特殊的string样式输出
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("asdfadsf{0:C}adsfasdf",b);//asdfadsf¥1,234.13adsfasdf
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = "asdfadsf"+b.ToString("C")+"adsfasdf";//asdfadsf¥1,234.13adsfasdf
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:C3}",b);//¥1,234.125
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("C3");//¥1,234.125
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

}",a);//十进制--12345678
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("d");//十进制--相同的类型,转换报错
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:e}",a);//指数--1.234568e+007
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("e");//指数--1.234125e+003
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

}",a);//定点数--12345678.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("f");//定点数--1234.13
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:n}",a);//数值--12,345,678.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("n");//数值--1,234.13
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

}",a);//十六进制--bc614e
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("x");//16--带有小数不能转换,出错
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

}",a);//通用为最紧凑--12345678
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("g");//通用为最紧凑--1234.12543
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:r}",a);//转来转去不损失精度--整数不允许用,报错
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = b.ToString("r");//转来转去不损失精度--1234.12543
©Å_ùªí(þeâwww.nfhot.comh$»*b) ©Å_ùªí(þeâwww.nfhot.comh$»*b) b = 4321.12543;
©Å_ùªí(þeâwww.nfhot.comh$»*b) a = 1234;
©Å_ùªí(þeâwww.nfhot.comh$»*b) //自定义模式输出:
©Å_ùªí(þeâwww.nfhot.comh$»*b)// 0 描述:占位符,如果可能,填充位
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:000000}",a);// 001234
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:000000}",b);// 004321
©Å_ùªí(þeâwww.nfhot.comh$»*b)// # 描述:占位符,如果可能,填充位
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

######}",a);// 1234
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0

######}",b);// 4321
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0

0####}",a);// 01234
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:0#0000}",b);// 004321
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)// . 描述:小数点
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:000.000}",a);//1234.000
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:000.000}",b);//4321.125
©Å_ùªí(þeâwww.nfhot.comh$»*b) b = 87654321.12543;
©Å_ùªí(þeâwww.nfhot.comh$»*b) a = 12345678;
©Å_ùªí(þeâwww.nfhot.comh$»*b)// , 描述:数字分组,也用于增倍器
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0,00}",a);// 12,345,678
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:0,00}",b);// 87,654,32
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0,}",a);// 12346
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:0,}",b);// 87654
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0,,}",a);// 12
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:0,,}",b);// 88
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0,,,}",a);// 0
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:0,,,}",b);// 0
©Å_ùªí(þeâwww.nfhot.comh$»*b)// % 描述:格式为百分数
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0%}",a);// 1234567800%
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0

%}",b);// 8765432113%
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:0.00%}",a);// 1234567800.00%
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0

.00%}",b);// 8765432112.54%
©Å_ùªí(þeâwww.nfhot.comh$»*b)// 'abc' 描述:显示单引号内的文本
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("{0:'文本'0}",a);// 文本12345678
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("{0:文本0}",b);// 文本87654321
©Å_ùªí(þeâwww.nfhot.comh$»*b)// \ 描述:后跟1要打印字的字符,也用于转移符\n等
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format("\"你好!\"");// "你好!"
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format("\\c\\books\\new\\we.asp");//\c\books\new\we.asp
©Å_ùªí(þeâwww.nfhot.comh$»*b)// @描述:后跟要打印字的字符,
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label1.Text = string.Format(@"""你好!"""); // "你好!"要打印"则需要输入两对才可以
©Å_ùªí(þeâwww.nfhot.comh$»*b)// Label2.Text = string.Format(@"\c\books\new\we.asp");//\c\books\new\we.asp
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)格式 原始数据 结 果
©Å_ùªí(þeâwww.nfhot.comh$»*b)"{0

}" 0.40 40%
©Å_ùªí(þeâwww.nfhot.comh$»*b)数字 {0:N2} 12.36
©Å_ùªí(þeâwww.nfhot.comh$»*b)数字 {0:N0} 13
©Å_ùªí(þeâwww.nfhot.comh$»*b)货币 {0:c2} $12.36
©Å_ùªí(þeâwww.nfhot.comh$»*b)货币 {0:c4} $12.3656
©Å_ùªí(þeâwww.nfhot.comh$»*b)货币 "¥{0:N2}" ¥12.36
©Å_ùªí(þeâwww.nfhot.comh$»*b)科学计数法 {0:E3} 1.23E+001
©Å_ùªí(þeâwww.nfhot.comh$»*b)百分数 {0

} 12.25% P and p present the same.
©Å_ùªí(þeâwww.nfhot.comh$»*b)日期 {0

} 2006年11月25日
©Å_ùªí(þeâwww.nfhot.comh$»*b)日期 {0

} 2006-11-25
©Å_ùªí(þeâwww.nfhot.comh$»*b)日期 {0

} 2006年11月25日 10:30
©Å_ùªí(þeâwww.nfhot.comh$»*b)日期 {0:F} 2006年11月25日 10:30:00
©Å_ùªí(þeâwww.nfhot.comh$»*b)日期 {0:s} 2006-11-26 10:30:00
©Å_ùªí(þeâwww.nfhot.comh$»*b)时间 {0

} 10:30:00
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)DateTime dt = DateTime.Now;
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = dt.ToString();//2005-11-5 13:21:25
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = dt.ToFileTime().ToString();//127756416859912816
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = dt.ToFileTimeUtc().ToString();//127756704859912816
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = dt.ToLocalTime().ToString();//2005-11-5 21:21:25
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = dt.ToLongDateString().ToString();//2005年11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label6.Text = dt.ToLongTimeString().ToString();//13:21:25
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label7.Text = dt.ToOADate().ToString();//38661.5565508218
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label8.Text = dt.ToShortDateString().ToString();//2005-11-5
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label9.Text = dt.ToShortTimeString().ToString();//13:21
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label10.Text = dt.ToUniversalTime().ToString();//2005-11-5 5:21:25
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = dt.Year.ToString();//2005
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = dt.Date.ToString();//2005-11-5 0:00:00
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = dt.DayOfWeek.ToString();//Saturday
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = dt.DayOfYear.ToString();//309
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = dt.Hour.ToString();//13
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label6.Text = dt.Millisecond.ToString();//441
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label7.Text = dt.Minute.ToString();//30
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label8.Text = dt.Month.ToString();//11
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label9.Text = dt.Second.ToString();//28
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label10.Text = dt.Ticks.ToString();//632667942284412864
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label11.Text = dt.TimeOfDay.ToString();//13:30:28.4412864
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = dt.ToString();//2005-11-5 13:47:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = dt.AddYears(1).ToString();//2006-11-5 13:47:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = dt.AddDays(1.1).ToString();//2005-11-6 16:11:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = dt.AddHours(1.1).ToString();//2005-11-5 14:53:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = dt.AddMilliseconds(1.1).ToString();//2005-11-5 13:47:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label6.Text = dt.AddMonths(1).ToString();//2005-12-5 13:47:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label7.Text = dt.AddSeconds(1.1).ToString();//2005-11-5 13:47:05
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label8.Text = dt.AddMinutes(1.1).ToString();//2005-11-5 13:48:10
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label9.Text = dt.AddTicks(1000).ToString();//2005-11-5 13:47:04
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label10.Text = dt.CompareTo(dt).ToString();//0
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label11.Text = dt.Add(?).ToString();//问号为一个时间段
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = dt.Equals("2005-11-6 16:11:04").ToString();//False
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = dt.Equals(dt).ToString();//True
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = dt.GetHashCode().ToString();//1474088234
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = dt.GetType().ToString();//System.DateTime
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = dt.GetTypeCode().ToString();//DateTime
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = dt.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = dt.GetDateTimeFormats('t')[0].ToString();//14:06
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = dt.GetDateTimeFormats('y')[0].ToString();//2005年11月
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = dt.GetDateTimeFormats('D')[0].ToString();//2005年11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label6.Text = dt.GetDateTimeFormats('D')[2].ToString();//星期六 2005 11 05
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label7.Text = dt.GetDateTimeFormats('D')[3].ToString();//星期六 2005年11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label8.Text = dt.GetDateTimeFormats('M')[0].ToString();//11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label9.Text = dt.GetDateTimeFormats('f')[0].ToString();//2005年11月5日 14:06
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label10.Text = dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label11.Text = dt.GetDateTimeFormats('r')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)Label1.Text = string.Format("{0

}",dt);//2005-11-5
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label2.Text = string.Format("{0

}",dt);//2005年11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label3.Text = string.Format("{0

}",dt);//2005年11月5日 14:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label4.Text = string.Format("{0:F}",dt);//2005年11月5日 14:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label5.Text = string.Format("{0

}",dt);//2005-11-5 14:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label6.Text = string.Format("{0:G}",dt);//2005-11-5 14:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label7.Text = string.Format("{0:M}",dt);//11月5日
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label8.Text = string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label9.Text = string.Format("{0:s}",dt);//2005-11-05T14:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label10.Text string.Format("{0:t}",dt);//14:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label11.Text = string.Format("{0

}",dt);//14:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label12.Text = string.Format("{0:u}",dt);//2005-11-05 14:23:23Z
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label13.Text = string.Format("{0:U}",dt);//2005年11月5日 6:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label14.Text = string.Format("{0:Y}",dt);//2005年11月
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label15.Text = string.Format("{0}",dt);//2005-11-5 14:23:23
©Å_ùªí(þeâwww.nfhot.comh$»*b)Label16.Text = string.Format("{0:yyyyMMddHHmmssffff}",dt);
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr1 =string.Format("{0:N1}",56789); //result: 56,789.0
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr2 =string.Format("{0:N2}",56789); //result: 56,789.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr3 =string.Format("{0:N3}",56789); //result: 56,789.000
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr8 =string.Format("{0:F1}",56789); //result: 56789.0
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr9 =string.Format("{0:F2}",56789); //result: 56789.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr11 =(56789 / 100.0).ToString("#.##"); //result: 567.89
©Å_ùªí(þeâwww.nfhot.comh$»*b)stringstr12 =(56789 / 100).ToString("#.##"); //result: 567
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)C 或 c
©Å_ùªí(þeâwww.nfhot.comh$»*b)货币
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:C}", 2.5); //$2.50
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:C}", -2.5); //($2.50)
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)D 或 d
©Å_ùªí(þeâwww.nfhot.comh$»*b)十进制数
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0

5}", 25); //00025
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)E 或 e
©Å_ùªí(þeâwww.nfhot.comh$»*b)科学型
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:E}", 250000); //2.500000E+005
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)F 或 f
©Å_ùªí(þeâwww.nfhot.comh$»*b)固定点
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:F2}", 25); //25.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:F0}", 25); //25
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)G 或 g
©Å_ùªí(þeâwww.nfhot.comh$»*b)常规
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:G}", 2.5); //2.5
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)N 或 n
©Å_ùªí(þeâwww.nfhot.comh$»*b)数字
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0:N}", 2500000); //2,500,000.00
©Å_ùªí(þeâwww.nfhot.comh$»*b)©Å_ùªí(þeâwww.nfhot.comh$»*b)X 或 x
©Å_ùªí(þeâwww.nfhot.comh$»*b)十六进制
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0

}", 250); //FA
©Å_ùªí(þeâwww.nfhot.comh$»*b)Console.Write("{0

}", 0xffff); //FFFF
©Å_ùªí(þeâwww.nfhot.comh$»*b)