string.Format("{0:f}",System.DateTime.Now) 结果为:2009年3月20日 15:37 string.Format("{0:F}",System.DateTime.Now) 结果为:2009年3月20日 15:37:52 string.Format("{0:g}",System.DateTime.Now) 结果为:2009-3-20 15:38 string.Format("{0:G}",System.DateTime.Now) 结果为:2009-3-20...
string currencyFormat = "{0:C}"; //默认格式,货币符号在前,小数点两位 string formattedValue = string.Format(currencyFormat, 1234.56); //输出为$1,234.56 复制代码 设置自定义格式: string customCurrencyFormat = "{0:C2}"; //设置小数点两位 string formattedValue = string.Format(customCurrencyFormat...
string.Format("{0:f}",System.DateTime.Now) 结果为:2009年3月20日 15:37 string.Format("{0:F}",System.DateTime.Now) 结果为:2009年3月20日 15:37:52 string.Format("{0:g}",System.DateTime.Now) 结果为:2009-3-20 15:38 string.Format("{0:G}",System.DateTime.Now) 结果为:2009-3-20...
s=String.Format("(C) Currency: . . . . . . . . {0:C}\n"+"(D) Decimal:. . . . . . . . . {0:D}\n"+"(E) Scientific: . . . . . . . {1:E}\n"+"(F) Fixed point:. . . . . . . {1:F}\n"+"(G) General:. . . . . . . . . {0:G}\n"+"(defau...
如果您需要指定特定的格式,可以使用string.Format()方法。例如: 代码语言:csharp 复制 decimalcurrency=123.45m;stringcurrencyString=string.Format("{0:C}",currency); 这个例子中,string.Format()方法会将currency变量格式化为带有货币符号的字符串表示,并将其存储在currencyString变量中。
String.Format("{0:(###) ###-###}", 18005551212); This will output "(800) 555-1212". 变量.ToString() 字符型转换 转为字符串 12345.ToString("n"); //生成 12,345.00 12345.ToString("C"); //生成 ¥12,345.00 12345.ToString("e"); //生成 1.234500e+004 12345...
Currency、C或c視需要顯示具有千位分隔符的數位;會顯示小數分隔符右邊的兩位數。 輸出是以系統地區設定為基礎。 例如,Format(1234567, "c")會傳回$1,234,567.00。 Fixed、F或f在小數分隔符右邊顯示至少一位數和兩位數。 例如,Format(1234567, "f")會傳回1234567.00。
s = String.Format(CultureInfo.InvariantCulture, _ "(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _ "(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _ "(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _ "(F) Fixed point:. . . . . . . {1:...
Format currency using a :C specifier. Format numbers using a :N specifier. Control the precision (number of values after the decimal point) using a number after the :N like {myNumber:N3}. Format percentages using the :P format specifier. Formatting currency and numbers depend on the end us...
DecimalDigitNumber,LetterNumber,OtherNumber,SpaceSeparator,LineSeparator,ParagraphSeparator,Control,Format,Surrogate,PrivateUse,ConnectorPunctuation,DashPunctuation,OpenPunctuation,ClosePunctuation,InitialQuotePunctuation,FinalQuotePunctuation,OtherPunctuation,MathSymbol,CurrencySymbol,ModifierSymbol,OtherSymbol,OtherNotAssigned...