Standard numeric format string usage instructions and Examples

Source: Internet
Author: User
// Standard numeric format string usage instructions and Examples
Class numberformat
{
Static void main ()
{
// {Index [, alignment] [: Format]}
// Index-an integer starting from scratch, indicating the elements to be formatted in the object list.
// Alignment-an optional integer indicating the minimum width. Fill the remaining part with spaces. Negative Numbers indicate left alignment, and positive numbers indicate right alignment.
// Format-format string. A string in the standard numeric format is in the form of "axx". A is a single letter, which is described as follows:
// C-currency, XX indicates the number of decimal places
// D-decimal, XX indicates the number of valid digits, which is not filled with zero and can only be used as an integer
// X-hexadecimal with the same usage as d
// E-index, XX indicates the number of decimal places
// F-fixed point, XX indicates the number of decimal places
// N-number, output the thousands separator, and the rest are the same as F
// G-regular, XX indicates the number of valid digits, which is shorter than E or F
// P-percentage, XX indicates the number of decimal places
// For example, the output of the following statement is: "| ¥-5.00 |-05 |-05 |-5.0 |-500.00% | 12345.7 | 12,345.7 |"
System. console. writeline ("| {0: c} | {0: D2} | {0, 4: D2} | {0,-5: F1} | {0: P2} | {1: f1} | {1: N1} | ",-5, 12345.67 );
}
}

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.