Format a numeric string and a string

Source: Internet
Author: User

Format a numeric string and a string
Syntax of format specifiers

Alignment specifier

A positive value indicates the right alignment, and a negative value indicates the left alignment. If the number of characters to be expressed is less than the number specified in the alignment specifier, spaces are used. If the number is more, the characters are ignored.

1         static void Main(string[] args)2         {3             var temp = 1000;4             Console.WriteLine("|{0,10}|", temp);5             Console.WriteLine("|{0,-10}|", temp);6             Console.WriteLine("|{0,3}|", temp);7         }

Format Field

1 var temp = 123.456789; 2 Console. writeLine ("{0: F3}", temp); // fixed point, retain the number of decimal places 3 Console. writeLine ("{0: C}", temp); // indicates the currency, depending on the PC region set 4 Console. writeLine ("{0: D10}", 123); // Console in decimal number 5. writeLine ("{0: G4}", temp); // retain the "number length" according to the description, and the last digit is rounded to 6 consoles. writeLine ("{0: X}", 123); // convert to hexadecimal (case sensitive) 7 Console. writeLine ("{0: N4}", 1234567,890123); // separate the numbers by commas. writeLine ("{0: P}", temp); // percentage 9 Console. writeLine ("{0: R}", temp); // 10 Console. writeLine ("{0: E3}", temp); // scientific notation (case sensitive)

 

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.