ASP.NET data format Format - DataFormatString

xiaoxiao2021-03-19  229

When we present data, do not presen a modified data to the user. For example, the amount is 10,000 yuan. If we display "10000" directly, it may cause the user to see a thousand or 100,000, causing the user's reading data. If we output 10,000 yuan to "NT $ 10,000", we will not only make more good reading, but also make users reduce the chance to make mistakes.

The following screens are equissitive results:

The above data is easier to read by using the DataGrid web control to be recorded in colors. To modify the output of the field, just set the DataFormatString property of the field; use the syntax as follows:

DataFormatString = "{0: Format string}"

We know that the {0} represents the data itself in the dataformatstring, and the format string behind the colon depends on the format that wants the data display; additionally, 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}, the output is "12.3". The common value formats are shown in the following table:

Format string information

"{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 common date format is shown in the following table:

Format Description Output Format

D streamlined Date format mm / dd / yyyy

D Detailed Date Format DDDD, MMMM DD, YYYY

F Complete Format (Long Date Short Time) DDDD, MMMM DD, YYYY HH: mm

Fly

Complete 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 / yyyyh: mm: ss

M, M Moon Format MMMM DD

s moderate date Time format YYYY-MM-DD HH: mm: SS

T simple time format hh: mm

T Detailed Time Format HH: MM: SS

转载请注明原文地址:https://www.9cbs.com/read-130151.html

New Post(0)