Asp.net| data when we render the data, we do not present the unmodified data to the user. For example, the amount of 10,000 yuan, if we directly display "10000", may lead to users as 1000 or 100,000, causing users to read data on the trouble. If we will be 10,000 yuan polished after the output for "nt$10,000", not only make it easier to read, but also allows users to reduce the chance of making mistakes.
To modify the output of a field, simply set the DataFormatString property of the field and use the following syntax:
dataformatstring= ' {0: format string} '
We know that {0} in dataformatstring represents the data itself, and the format string after the colon represents the format in which you want the data to appear, and you can specify the number of digits to display after the specified format symbol. For example, the original data is "12.34", if the format is set to {0:n1}, then the output is "12.3". Its commonly used numerical formats are shown in the following table:
format string |
Information |
Results |
' {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 |
Its commonly used date formats are shown in the following table:
Format Description Output format
D Compact Date format mm/dd/yyyy
D Detail Date format dddd, MMMM DD, yyyy
F Full Format (long date + short time) dddd, MMMM dd, yyyy hh:mm
F
Full Date 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 time format Yyyy-mm-dd HH:MM:SS
T streamlined time format hh:mm
T Verbose time Format HH:mm:ss