Formatting numeric strings

Source: Internet
Author: User

Syntax for format specifiers

Justification specifier

Positive numbers indicate right alignment, and negative numbers indicate left alignment. If the number of characters you want to represent is less than the number specified in the alignment specifier, a space is filled in, and if more, it is ignored.

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

Format field

1var temp =123.456789;2 Console.WriteLine ("{0:F3}", temp);//Fixed point, number of decimal digits reserved3 Console.WriteLine ("{0:C}", temp);//Represents currency, depending on the locale of the PC4 Console.WriteLine ("{0:D10}",123);//Decimal number5 Console.WriteLine ("{0:G4}", temp);//Keep "number Length" according to the specifier, and the last one rounded6 Console.WriteLine ("{0:X}",123);//Turn 16 binary (case sensitive)7 Console.WriteLine ("{0:N4}1234567,890123"; Span style= "color: #008000;" >// 8 Console.WriteLine ( "{0:p}", temp); // 9 Console.WriteLine ( "{0:r} //10 Console.WriteLine (  "{0:e3}// scientific notation (case-sensitive)           

Formatting numeric strings

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.