//格式为sring输出 Label1.Text = 文字列。 フォーマット("asdfadsf{0}adsfasdf",a); Label2.Text = "asdfadsf"+a.ToString()+"adsfasdf"; Label1.Text = 文字列。 Format("asdfadsf{0:C}adsfasdf",a); ASDFADSF¥1,234.00adsFASDF Label2.Text = "asdfadsf"+a.ToString("C")+"adsfasdf"; ASDFADSF¥1,234.00adsFASDF
ダブルb = 1234.12543; a = 12345678; このフォーマットは特別な文字列スタイルの出力です Label1.Text = 文字列。 Format("asdfadsf{0:C}adsfasdf",b); ASDFADSF¥1,234.13adsFASDF Label2.Text = "asdfadsf"+b.ToString("C")+"adsfasdf"; ASDFADSF¥1,234.13adsFASDF Label1.Text = 文字列。 Format("{0:C3}",b); ¥1,234.125 Label2.Text = b.ToString("C3"); ¥1,234.125 Label1.Text = 文字列。 Format("{0:d}",a); 十進法 - 12345678 Label2.Text = b.ToString("d"); 十進法 - 同じタイプ、換算誤差 Label1.Text = 文字列。 Format("{0:e}",a); インデックス - 1.234568e+007 Label2.Text = b.ToString("e"); インデックス - 1.234125E+003
Label1.Text = 文字列。 Format("{0:f}",a); 固定点数 - 12345678.00 Label2.Text = b.ToString("f"); 不動点番号 - 1234.13 Label1.Text = 文字列。 Format("{0:n}",a); 価値 - 12,345,678.00 Label2.Text = b.ToString("n"); 価値 - 1,234.13 Label1.Text = 文字列。 Format("{0:x}",a); HEX - BC614E Label2.Text = b.ToString("x"); 16 - 小数点では変換できず、エラーが発生しました Label1.Text = 文字列。 Format("{0:g}",a); ユニバーサルが最もコンパクトです - 12345678 Label2.Text = b.ToString("g"); ユニバーサルが最もコンパクトで、1234.12543 Label1.Text = 文字列。 Format("{0:r}",a); 精度を失わずに回転させる方法 - 整数の使用は禁止され、誤差が報告されます Label2.Text = b.ToString("r"); 精度を損なわずにターンアラウンド - 1234.12543
b = 4321.12543; a = 1234; カスタムモード出力: 0 説明:可能であれば、プレースホルダーをビットに埋めてください Label1.Text = 文字列。 Format("{0:00000},a); // 001234 Label2.Text = 文字列。 Format("{0:000000},b); // 004321 # 説明:可能なら仮の名を埋めてください Label1.Text = 文字列。 Format("{0:#######}",a); // 1234 Label2.Text = 文字列。 Format("{0:#######}",b); // 4321 Label1.Text = 文字列。 Format("{0:#0####}",a); // 01234 Label2.Text = 文字列。 Format("{0:0#0000},b); // 004321
// . 説明:小数点 Label1.Text = 文字列。 Format("{0:000.000},a); //1234.000 Label2.Text = 文字列。 Format("{0:000.00}",b); //4321.125 b = 87654321.12543; a = 12345678; 、説明:デジタルグルーピング、乗算器でも使用されます Label1.Text = 文字列。 Format("{0:0,00}",a); // 12,345,678 Label2.Text = 文字列。 Format("{0:0,00}",b); // 87,654,32 Label1.Text = 文字列。 Format("{0:0,}",a); // 12346 Label2.Text = 文字列。 Format("{0:0,}",b); // 87654 Label1.Text = 文字列。 Format("{0:0,,}",a); // 12 Label2.Text = 文字列。 Format("{0:0,,}",b); // 88 Label1.Text = 文字列。 Format("{0:0,,,}",a); // 0 Label2.Text = 文字列。 Format("{0:0,,,}",b); 0 // % 説明:パーセンテージ形式 // ラベル1.テキスト=文字列。 Format("{0:0%}",a); 1234567800% // Label2.Text = 文字列。 Format("{0:#%}",b); 8765432113% // Label1.Text = 文字列。 Format("{0:0.00%}",a); 123456780.00% // Label2.Text = 文字列。 Format("{0:#.00%}",b); 876543212.54% // 'abc' 説明:シングルクォート内にテキストを表示する // ラベル1.テキスト=文字列。 format("{0:'text'0}",a); テキスト12345678 // ラベル2.テキスト=文字列。 format("{0:text 0}",b); テキスト87654321 // / 説明:1の後に印刷する文字が続き、/nなどの文字転送にも使われます。 // ラベル1.テキスト=文字列。 フォーマット("/"こんにちは! /""); 「こんにちは!」 Label2.Text = 文字列。 フォーマット(「//c//books//new//we.asp」); c/books/new/we.asp // @描述:印刷する文字の後に続きます。// Label1.Text = 文字列。 Format(@""こんにちは! """); 「こんにちは!」 「印刷するには、//に2組のペアを入力する必要があります。Label2.Text = 文字列です。 フォーマット(@"/c/books/new/we.asp"); c/books/new/we.asp パーセンテージ形式は「p」パラメータを使うべきです。 Format Raw Data Result "{0:P}" 0.40 40%
番号 {0:N2} 12.36 ナンバー {0:N0} 13 通貨 {0:c2} $12.36 通貨 {0:c4} $12.3656 通貨 「¥{0:N2}」¥12.36 科学的表記法 {0:E3} 1.23E+001 パーセンテージ {0:P} 12.25% Pとpは同じです。 日付 {0:D} 2006年11月25日 日付 {0:d} 2006-11-25 日付 {0:f} 2006年11月25日 10:30 (UTC) 日付 {0:F} 2006年11月25日 10:30:00 (UTC) 日付 {0:s} 2006-11-26 10:30:00 時間 {0:T} 10:30:00
DateTime dt = DateTime.Now; Label1.Text = dt。 ToString(); //2005-11-5 13:21:25 Label2.Text = dt。 ToFileTime()。 ToString(); //127756416859912816 ラベル3.テキスト = dt。 ToFileTimeUtc()。 ToString(); //127756704859912816 ラベル4.テキスト=dt。 ToLocalTime()。 ToString(); //2005-11-5 21:21:25 ラベル5.テキスト=dt。 ToLongDateString()。 ToString(); 2005年11月5日 ラベル6.テキスト=dt。 ToLongTimeString()。 ToString(); //13:21:25 Label7.Text = dt. ToOADate()。 ToString(); //38661.5565508218 ラベル8.テキスト = dt。 ToShortDateString()。 ToString(); //2005-11-5 Label9.Text = dt。 ToShortTimeString()。 ToString(); //13:21 Label10.Text = dt。 ToUniversalTime()。 ToString(); //2005-11-5 5:21:25
Label1.Text = dt。 Year.ToString(); //2005 Label2.Text = dt。 Date.ToString(); //2005-11-5 0:00:00 ラベル3.テキスト = dt。 DayOfWeek.ToString(); 土曜日 ラベル4.テキスト=dt。 DayOfYear.ToString(); //309 ラベル5.テキスト=dt。 Hour.ToString(); //13 ラベル6.テキスト=dt。 Millisecond.ToString(); //441 Label7.Text = dt. Minute.ToString(); //30 ラベル8.テキスト = dt。 月経・ストリング(); //11 Label9.Text = dt。 第二の弦(ToString)); 28 ラベル10.テキスト = dt。 Ticks.ToString(); 632667942284412864 Label11.Text = dt。 TimeOfDay.ToString(); 13:30:28.4412864 ラベル1.テキスト=dt。 ToString(); 2005年11月5日 13:47:04 ラベル2.テキスト = dt。 AddYears(1)。 ToString(); 2006-11-5 13:47:04 ラベル3.テキスト = dt。 AddDays(1.1)。 ToString(); 2005-11-6 16:11:04 ラベル4.テキスト=dt。 AddHours(1.1) ToString(); 2005-11-5 14:53:04 ラベル5.テキスト = dt。 AddMilliseconds(1.1)。 ToString(); 2005-11-5 13:47:04 Label6.テキスト=dt。 AddMonths(1)。 ToString(); 2005-12-5 13:47:04 Label7.Text = dt. AddSeconds(1.1)。 ToString(); 2005-11-5 13:47:05 ラベル8.テキスト=dt。 AddMinutes(1.1) ToString(); 2005-11-5 13:48:10 ラベル9.テキスト=dt。 AddTicks(1000)。 ToString(); 2005-11-5 13:47:04 Label10.テキスト=dt。 CompareTo(dt)。 ToString(); 0 ラベル11.テキスト = dt。 Add(?)。 ToString(); 疑問符は期間を示しています。ラベル1.テキスト=dt。 Equals(「2005-11-6 16:11:04」)。 ToString(); 偽ラベル2.テキスト = dt。 Equals(dt)。 ToString(); 真の表示3.テキスト=dt。 GetHashCode()。 ToString(); 1474088234 ラベル4.テキスト=dt。 GetType()。 ToString(); System.DateTime Label5.Text = dt. GetTypeCode()。 ToString(); DateTime ラベル1.Text = dt。 GetDateTimeFormats('s')[0]。 ToString(); 2005-11-05T 14:06:25 ラベル2.テキスト = dt。 GetDateTimeFormats('t')[0]. ToString(); 14:06 ラベル3.テキスト = dt。 GetDateTimeFormats('y')[0]. ToString(); 2005年11月 ラベル4.テキスト = dt。 GetDateTimeFormats('D')[0]. ToString(); 2005年11月5日 ラベル5.テキスト = dt。 GetDateTimeFormats('D')[1]. ToString(); 2005年 11月5日 ラベル6.テキスト=dt。 GetDateTimeFormats('D')[2]. ToString(); 2005年土曜日 11 05 ラベル7.テキスト=dt。 GetDateTimeFormats('D')[3]。 ToString(); 2005年11月5日土曜日 Label8.Text = dt. GetDateTimeFormats('M')[0]. ToString(); 11月5日 ラベル9。テキスト=dt。 GetDateTimeFormats('f')[0]. ToString(); 2005年11月5日 14:06 Label10.Text = dt。 GetDateTimeFormats('g')[0]. ToString(); 2005-11-5 14:06 Label11.Text = dt. GetDateTimeFormats('r')[0]. ToString(); 2005年11月5日(土)14:06:25 GMT ラベル1.Text=文字列。 Format("{0:d}",dt); 2005-11-5 Label2.Text = 文字列。 Format("{0:D}",dt); 2005年11月5日 Label3.Text = 文字列。 Format("{0:f}",dt); 2005年11月5日 14:23 Label4.Text = 文字列。 Format("{0:F}",dt); 2005年11月5日 14:23:23 ラベル5.テキスト=文字列。 Format("{0:g}",dt); 2005-11-5 14:23 Label6.Text = 文字列。 Format("{0:G}",dt); 2005年11月5日 14:23:23 ラベル7.テキスト=文字列。 Format("{0:M}",dt); 11月5日 ラベル8.テキスト=文字列。 Format("{0:R}",dt); 2005年11月5日(土)14:23:23 GMT Label9.Text = 文字列。 Format("{0:s}",dt); 2005-11-05T14:23:23 ラベル10.テキスト文字列。 Format("{0:t}",dt); 14:23 Label11.Text = 文字列。 Format("{0:T}",dt); 14:23:23 Label12.Text = 文字列。 Format("{0:u}",dt); 2005-11-05 14:23:23Z Label13.Text = 文字列。 Format("{0:U}",dt); 2005年1月5日 午前6時23分23秒 Label14.Text = 文字列。 Format("{0:Y}",dt); 2005年11月 Label15.Text = 文字列。 フォーマット("{0}"、dt); 2005-11-5 14:23:23 label16.text = 文字列。 Format("{0:yyyyMMddHHmmssffff},dt); stringstr1 =文字列。 Format("{0:N1}",56789); 結果:56,789.0 stringstr2 =文字列。 Format("{0:N2}",56789); 結果:56,789.00 stringstr3 =文字列。 Format("{0:N3}",56789); 結果:56,789,000票 stringstr8 =文字列。 Format("{0:F1}",56789); 結果:56789.0 stringstr9 =文字列。 Format("{0:F2}",56789); 結果:56789.00 stringstr11 =(56789 / 100.0)。 ToString("#.##"); 結果:567.89 stringstr12 =(56789 / 100)。 ToString("#.##"); 結果:567
CまたはC 通貨 Console.Write("{0:C}", 2.5); 2.50ドル Console.Write("{0:C}", -2.5); ($2.50)
Dまたはd 十進数 Console.Write("{0:D5}", 25); //00025
EまたはE 科学的タイプ Console.Write("{0:E}", 250000); 2.500000E+005
FかFか 固定点 Console.Write("{0:F2}", 25); //25.00 Console.Write("{0:F0}", 25); //25
Gまたはg レギュラー Console.Write("{0:G}", 2.5); //2.5
n または n 番号 Console.Write("{0:N}", 2500000); //2,500,000.00
XまたはX 六進制 Console.Write("{0:X}", 250); FA Console.Write("{0:X}", 0xffff); FFFF |