Int a = 12345678;
// Output in the sring format
// Label1.Text = string. Format ("asdfadsf {0} adsfasdf", );
// Label2.Text = "asdfadsf" + a. ToString () + "adsfasdf ";
// Label1.Text = string. Format ("asdfadsf {0: C} adsfasdf", a); // asdfadsf ¥1,234.00 adsfasdf
// Label2.Text = "asdfadsf" + a. ToString ("C") + "adsfasdf"; // asdfadsf ¥0. 1,234.00 adsfasdf
Double B = 1234.12543;
A = 12345678;
// Output in special string format
// Label1.Text = string. Format ("asdfadsf {0: C} adsfasdf", B); // asdfadsf ¥1,234.13 adsfasdf
// Label2.Text = "asdfadsf" + B. ToString ("C") + "adsfasdf"; // asdfadsf ¥0. 1,234.13 adsfasdf
// Label1.Text = string. Format ("{0: C3}", B); // ¥1,234.125
// Label2.Text = B. ToString ("C3"); // ¥1,234.125
// Label1.Text = string. Format ("{0: d}", a); // in decimal Format -- 12345678
// Label2.Text = B. ToString ("d"); // decimal -- same type, conversion error
// Label1.Text = string. Format ("{0: e}", a); // index -- 1.234568e + 007
// Label2.Text = B. ToString ("e"); // index -- 1.234125e + 003
// Label1.Text = string. Format ("{0: f}", a); // set the number of points -- 12345678.00
// Label2.Text = B. ToString ("f"); // set the number of points -- 1234.13
// Label1.Text = string. Format ("{0: n}", a); // value -- 12,345,678.00
// Label2.Text = B. ToString ("n"); // value -- 1,234.13
// Label1.Text = string. Format ("{0: x}", a); // hexadecimal -- bc614e
// Label2.Text = B. ToString ("x"); // 16 -- cannot be converted with decimals, error
// Label1.Text = string. Format ("{0: g}", a); // use the most compact mode -- 12345678
// Label2.Text = B. ToString ("g"); // use the most compact version -- 1234.12543
// Label1.Text = string. Format ("{0: r}", a); // transfer without loss of precision -- integers are not allowed and an error is returned.
// Label2.Text = B. ToString ("r"); // transfer without loss of precision -- 1234.12543
B = 4321.12543;
A = 1234;
// Custom mode output:
// 0 Description: placeholder. If possible, fill the position
// Label1.Text = string. Format ("{0: 00}", a); // 001234
// Label2.Text = string. Format ("{0: 00}", B); // 004321
// # Description: placeholder. If possible, it indicates the filling space.
// Label1.Text = string. Format ("{0: #######}", a); // 1234
// Label2.Text = string. Format ("{0: #######}", B); // 4321
// Label1.Text = string. Format ("{0: #0 ####}", a); // 01234
// Label2.Text = string. Format ("{0 #0000}", B); // 004321
//. Description: decimal point
// Label1.Text = string. Format ("{0: 000. 000}", a); // 1234.000
// Label2.Text = string. Format ("{0: 000. 000}", B); // 4321.125
B = 87654321.12543;
A = 12345678;
//, Description: Numeric grouping, also used for the Multiplier
// Label1.Text = string. Format ("{0, 00}", a); // 12,345,678
// Label2.Text = string. Format ("{0, 00}", B); // 87,654, 32
// Label1.Text = string. Format ("{0: 0,}", a); // 12346
// Label2.Text = string. Format ("{0: 0,}", B); // 87654
// Label1.Text = string. Format ("{0: 0,}", a); // 12
// Label2.Text = string. Format ("{0: 0,}", B); // 88
// Label1.Text = string. Format ("{0: 0, ,}", a); // 0
// Label2.Text = string. Format ("{0: 0, ,}", B); // 0
// % Description: The format is percent.
// Label1.Text = string. Format ("{0%}", a); // 1234567800%
// Label2.Text = string. Format ("{0: # %}", B); // 8765432113%
// Label1.Text = string. Format ("{0. 00%}", a); // 1234567800.00%
// Label2.Text = string. Format ("{0: #. 00%}", B); // 8765432112.54%
// 'Abc' Description: displays the text in single quotes.
// Label1.Text = string. Format ("{0: 'text' 0}", a); // text 12345678
// Label2.Text = string. Format ("{0: Text 0}", B); // text 87654321
// \ Description: it is followed by a character that needs to be printed. It is also used for escape characters, such as \ n.
// Label1.Text = string. Format ("\" Hello! \ ""); // "Hello! "
// Label2.Text = string. Format ("\ c \ books \ new \ we. asp"); // \ c \ books \ new \ we. asp
// @ Description: followed by the characters to be printed,
// Label1.Text = string. Format (@ "Hello! "); //" Hello! "Print" requires two pairs.
// Label2.Text = string. Format (@ "\ c \ books \ new \ we. asp"); // \ c \ books \ new \ we. asp
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.