Number formatting output

Source: Internet
Author: User
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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.