「C#」String.Formatで数値をカンマ変更するサンプル
書式
int 変数名A =値1
String.Format(“{0:#,0}", 変数名A)
double 変数名B =値2
String.Format(“{0:#,0.0000}", 変数名B)
使用例
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
//整数値をカンマ編集
int kk = 1234567;
Console.WriteLine("結果1: " + String.Format("{0:#,0}", kk));
//小数値をカンマ編集
double hh = 56789.123;
Console.WriteLine("結果2: " + String.Format("{0:#,0.0000}", hh));
Console.WriteLine("結果3: " + String.Format("{0:#,0.####}", hh));
Console.ReadKey();
}
}
}
実行結果
結果1: 1,234,567
結果2: 56,789.1230
結果3: 56,789.123