Format -- DataFormatString of ASP. NET data Format

Source: Internet
Author: User

When presenting data, do not present unmodified data to users. For example, if the amount is 10 thousand RMB, If we directly display "10000", the user may be treated as one thousand or 100,000, causing the user to read data. If we make the final modification of 10 thousand yuan into "NT $10,000", it will not only make reading better, but also reduce the chance of making mistakes.

To modify the output of a field, you only need to set the DataFormatString attribute of the field. The syntax is as follows:

DataFormatString = "{0: Format String }"

We know that {0} In DataFormatString represents the data itself, while the format string after the colon represents the format that we want the data to display; in addition, after the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "12.34" and the format is set to {0: N1}, the output is "12.3 」. The common numeric format is shown in the following table:

Format String Materials Result
"{0: C }" 12345.6789 $12,345.68
"{0: C }" -12345.6789 ($12,345.68)
"{0: D }" 12345 12345
"{0: D8 }" 12345 00012345
"{0: E }" 12345.6789 1234568E + 004
"{0: E10 }" 12345.6789 1.2345678900E + 004
"{0: F }" 12345.6789 12345.68
"{0: F0 }" 12345.6789 12346
"{0: G }" 12345.6789 12345.6789
"{0: G7 }" 123456789 1.234568E8
"{0: N }" 12345.6789 12,345.68
"{0: N4 }" 123456789 123,456,789.0000
"Total: {0: C }" 12345.6789 Total: $12345.68
 

The commonly used date formats are shown in the following table:

Format description output format
D. Simplified Date Format: MM/dd/yyyy
D detailed Date Format: dddd, MMMM dd, yyyy
F full format (long date + short time) dddd, MMMM dd, yyyy HH: mm
F
Complete Date and Time Format
(Long date + long time)
Dddd, MMMM dd, yyyy HH: mm: ss
G General Format (short date + short time) MM/dd/yyyy HH: mm
G General Format (short date + long time) MM/dd/yyyy HH: mm: ss
M, M month/day format MMMM dd
S moderate Date and Time Format: yyyy-MM-dd HH: mm: ss
T simplified time format HH: mm
T detailed time format HH: mm: ss

The pace of pursuit will never stop...



The author reads Yu Wen

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.