gridview column of numbers, currency and date format

form grammar result Note
digital {0: N2} 12.36
digital {0: N0} 13
currency {0:c2} $12.36
currency {0: CH4} $12.3656
currency "¥{0:N2}" ¥12.36
Scientific notation {0: E3} 1.23E + 001
percentage {0:P} 12.25% P and p present the same.
date {0:D} November 25, 2006
date {0:d} 2006-11-25
date {0:f} 2006 at 10:30 on November 25
date {0:F} November 25, 2006 10:30:00
date {0:s} 2006-11-26 10:30:00
time {0:T} 10:30:00

When setting gridview template column and other data-bound control, always set the format displayed here after I check out some of the statistics.
Another option is a conventional display the default database format.


Rounded to two decimal places:

double dValue = 0.2356;
double result = System.Math.Round(dValue,2);

or

Directly i.ToString ( "0.00")

 

format

date:

ToString("yyyy-MM-dd")

Return 2004-9-7

time:

ataFormatString="{0: HH:mm:ss}"

(:) time separator. In some locales, other characters represent the time separator. Time delimiter when formatting time values hours, minutes and seconds. Actual character formatted output as a time determined by the separator system LocaleID value.
(/) The date separator. In some locales, other characters represent the date separator. Date separator in the format hours of the next day value date, month and year. Formatted output as the date separator actual character determined by your locale.
(%) Is used to indicate whether trailing What letter, then characters should be read in a single-letter format. It is also used to indicate single-letter format to be read in a user-defined format. For more information, please see below.
d Display the day number without leading zeros (e.g., 1). If this is the digital format only user-defined characters, use% d.
dd Display the day with leading zeros (e.g., 01).
ddd Display the day as an abbreviation (e.g., Sun).
dddd Display the day as a full name (for example, Sunday).
M Displays the month number without leading zeros (e.g., denoted as January 1). If this is the digital format only user-defined characters, use% M.
MM is the month with digital displays leading zeros (for example, 01/12/01). 
MMM displays the month as an abbreviation (for example, Jan).
MMMM Displays the month as a full month name (for example, January).
gg Display Times / era string (e.g., the AD)
H to 12-hour digital hour display without leading zeros (e.g., 1:15:15 PM). If this is the digital format only user-defined characters, use% h.
hh hour to 12-hour digital display with leading zeros (e.g. 01:15:15 PM).
H using 24-hour clock is displayed as the hour with no leading zeros (e.g., 1:15:15). If this is the digital format only user-defined characters, use% H.
HH hour 24-hour format will be displayed as a number (e.g. 01:15:15) with leading zeros.
m Displays the minute number without leading zeros (e.g., 12: 1: 15). If this format is user-defined number of unique characters, use% m.
mm Displays the minute number (e.g. 12:01:15) with leading zeros.
s Displays the second number without leading zeros (for example, 12: 15: 5). If this is the digital format only user-defined characters, use% s.
ss Displays the second number with leading zeros (e.g. 12:15:05).
F shows the fraction of a second. For example, ff the accurate to hundredths of a second display, and to display the precise ffff millionth of a second. User-defined formats may be used in up to seven symbol f. If this is the digital format only user-defined characters, use% f. 
T 12-hour, and one hour before noon any display uppercase A, any of one hour between 11:59 PM noon display uppercase P. If this is the digital format of the user-defined unique characters, use the% t.
tt 12-hour, one hour and any display uppercase AM noon; for either one hour between 11:59 PM noon display uppercase PM.
The year y (0-9) are shown without a number of leading zeros. If this is the digital format only user-defined characters, use% y.
Year (if applicable) yy are displayed in two-digit format with leading zeros. 
Year yyy displayed in a four-digit format.
Year yyyy displayed in a four-digit format.
z show time zone offset without leading zeros (e.g., -8). If this is the digital format only user-defined characters, use% z.
zz display time zone offset with leading zeros (e.g. -08)
ZZZ display the complete time zone offset (e.g. -08: 00)

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2007/04/24/725835.html

Guess you like

Origin blog.csdn.net/weixin_34403693/article/details/93495916