double[] numbers= {1054.32179, -195489100.8377, 1.0437E21,
-1.0573e-05};
string[] specifiers = { "C", "E", "e", "F", "G", "N", "P",
"R", "#,000.000", "0.###E-000"};
foreach (double number in numbers)
{
Console.WriteLine("Formatting of {0}:", number);
foreach (string specifier in specifiers)
Console.WriteLine(" {0,5}: {1}",
specifier, number.ToString(specifier));
Console.WriteLine();
}
// The example displays the following output to the console:
// Formatting of 1054.32179:
// C: $1,054.32
// E: 1.054322E+003
// e: 1.054322e+003
// F: 1054.32
// G: 1054.32179
// N: 1,054.32
// P: 105,432.18 %
// R: 1054.32179
// #,000.000: 1,054.322
// 0.###E-000: 1.054E003
//
// Formatting of -195489100.8377:
// C: ($195,489,100.84)
// E: -1.954891E+008
// e: -1.954891e+008
// F: -195489100.84
// G: -195489100.8377
// N: -195,489,100.84
// P: -19,548,910,083.77 %
// R: -195489100.8377
// #,000.000: -195,489,100.838
// 0.###E-000: -1.955E008
//
// Formatting of 1.0437E+21:
// C: $1,043,700,000,000,000,000,000.00
// E: 1.043700E+021
// e: 1.043700e+021
// F: 1043700000000000000000.00
// G: 1.0437E+21
// N: 1,043,700,000,000,000,000,000.00
// P: 104,370,000,000,000,000,000,000.00 %
// R: 1.0437E+21
// #,000.000: 1,043,700,000,000,000,000,000.000
// 0.###E-000: 1.044E021
//
// Formatting of -1.0573E-05:
// C: $0.00
// E: -1.057300E-005
// e: -1.057300e-005
// F: 0.00
// G: -1.0573E-05
// N: 0.00
// P: 0.00 %
// R: -1.0573E-05
// #,000.000: 000.000
// 0.###E-000: -1.057E-005
-
-
-
- this.TextBox7.Text = System.DateTime.Now.ToString("d");
-
-
-
-
-
- this.TextBox8.Text = System.DateTime.Now.ToString("F");
-
-
-
- this.TextBox9.Text = System.DateTime.Now.ToString("f");
-
-
-
-
-
- this.TextBox10.Text = System.DateTime.Now.ToString("G");
-
-
-
- this.TextBox11.Text = System.DateTime.Now.ToString("g");
-
-
-
-
-
- this.TextBox12.Text = System.DateTime.Now.ToString("T");
-
-
-
- this.TextBox13.Text = System.DateTime.Now.ToString("t");
-
-
-
-
-
- this.TextBox14.Text = System.DateTime.Now.ToString("U");
-
-
-
- this.TextBox15.Text = System.DateTime.Now.ToString("u");
-
-
-
-
-
- this.TextBox16.Text = System.DateTime.Now.ToString("m");
-
- this.TextBox16.Text = System.DateTime.Now.ToString("M");
-
-
-
- this.TextBox17.Text = System.DateTime.Now.ToString("r");
-
- this.TextBox17.Text = System.DateTime.Now.ToString("R");
-
-
-
- this.TextBox19.Text = System.DateTime.Now.ToString("y");
-
- this.TextBox19.Text = System.DateTime.Now.ToString("Y");
-
-
-
- this.TextBox20.Text = System.DateTime.Now.ToString("o");
-
- this.TextBox20.Text = System.DateTime.Now.ToString("O");
-
-
-
- this.TextBox18.Text = System.DateTime.Now.ToString("s");
-
-
-
- this.TextBox21.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff");
-
-
-
- this.TextBox22.Text = System.DateTime.Now.ToString("yyyy年MM月dd HH时mm分ss秒");
-
-
-
-
-
-
-
- this.TextBox1.Text = System.DateTime.Now.ToString("dddd, MMMM dd yyyy");
-
-
-
- this.TextBox2.Text = System.DateTime.Now.ToString("ddd, MMM d \"'\"yy");
-
-
-
- this.TextBox3.Text = System.DateTime.Now.ToString("dddd, MMMM dd");
-
-
-
- this.TextBox4.Text = System.DateTime.Now.ToString("M/yy");
-
-
-
- this.TextBox5.Text = System.DateTime.Now.ToString("dd-MM-yy");
-
-
-
- 字符型转换 转为字符串
-
- 12345.ToString("n");
-
- 12345.ToString("C");
-
- 12345.ToString("e");
-
- 12345.ToString("f4");
-
- 12345.ToString("x");
-
- 12345.ToString("p");