string.Formatメソッドや、文字列補間(string interpolation) で行います。
string.Format の場合
-
C#
int intValue1 = 5800; string formatValue = string.Format("合計は{0:#,0}円です。", intValue1); // 結果 = "合計は5,800円です。" Console.WriteLine(formatValue);
-
VB.NET
dim intValue1 As Integer = 5800 dim formatValue As string = string.Format("合計は{0:#,0}円です。", intValue1) ' 結果 = "合計は5,800円です。" Console.WriteLine(formatValue)
文字列補間(string interpolation) の場合
-
C#
C#6(Visual Studio 2015, .NET Framework 4.6) 以上のバージョンが必要
int intValue2 = 6800; string formatValue2 = $"合計は{intValue2:#,0}円です。"; // 結果 = "合計は6,800円です。" Console.WriteLine(formatValue2);
-
VB.NET
Visual Basic 14(Visual Studio 2015, .NET Framework 4.6) 以上のバージョンが必要
dim intValue2 As Integer = 6800 dim formatValue2 As string = $"合計は{intValue2:#,0}円です。" ' 結果 = "合計は6,800円です。" Console.WriteLine(formatValue2)
サンプルコードのダウンロード
サンプルコードの実行には Microsoft Visual Studio 2015 以上のバージョンが必要です。 2015以外のバージョンではプロジェクトを開いた際にファイルの変換が必要な場合があります。その場合は変換後に実行してください。検証環境
- Microsoft Visual Studio Professional 2017 Version 15.7.3
- Microsoft .NET Framework Version 4.7.03190
- Microsoft Windows 10 Pro Version 1809 OS Build 17763.439