いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

数値のカンマ付け (書式設定, string.Format)


忘れない内にメモメモ。


数値をカンマ付けにフォーマットするには、以下の書式を利用します。

{0:N0}

コロンの後にNを付ける事で、カンマ付けされます。
Nの後ろの数値は、小数点の桁数です。0にしているので上記の場合は小数点は表示されません。


以下、サンプルです。

#region NumberFormatSamples-02
    public class NumberFormatSamples02 : IExecutable {

        public void Execute() {

            int i = 123456;
            Console.WriteLine("{0:N0}", i);
        }
    }
#endregion


以下、参照したリソースです。