字符
說明
示例
輸出
C 貨幣 string.Format("{0:C3}", 2) $2.000 D 十進制 string.Format("{0:D3}", 2) 002 E 科學計數法 1.20E+001 1.20E+001 G 常規 string.Format("{0:G}", 2) 2 N 用分號隔開的數字 string.Format("{0:N}", 250000) 250,000.00 X 十六進制 string.Format("{0:X000}", 12) CThere really isnt any formatting within a strong, beyond its alignment. Alignment works for any argument being printed in a String.Format call.
Sample Generates String.Format("->{1,10}<-", "Hello"); -> Hello<- String.Format("->{1,-10}<-", "Hello"); ->Hello <-
Basic number formatting specifiers:
Specifier Type Format
Output
(Passed
Double 1.42)
Output
(Passed
Int -12400)
Custom number formatting:
Specifier