「C#入門」ToString関数で数値をカンマ変更する

書式
int 変数名A = 値1
変数名A..ToString(“#,0")
double 変数名B = 値2
変数名B.ToString(“#,0.####")

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
//整数値をカンマ編集
int kk = 1234567;
Console.WriteLine("結果1: "+kk.ToString("#,0"));
//小数値をカンマ編集
double d = 45678.901;
Console.WriteLine("結果2: "+d.ToString("#,0.####"));
Console.WriteLine("結果3: "+d.ToString("#,0.0000"));
Console.ReadKey();
}
}
}
using System; using System.Text.RegularExpressions; namespace ConsoleApplicationSample { class Program { static void Main(string[] args) { //整数値をカンマ編集 int kk = 1234567; Console.WriteLine("結果1: "+kk.ToString("#,0")); //小数値をカンマ編集 double d = 45678.901; Console.WriteLine("結果2: "+d.ToString("#,0.####")); Console.WriteLine("結果3: "+d.ToString("#,0.0000")); Console.ReadKey(); } } }
using System;
using System.Text.RegularExpressions;

namespace ConsoleApplicationSample
{
    class Program
    {
        static void Main(string[] args)
        {
            //整数値をカンマ編集
            int kk = 1234567;
            Console.WriteLine("結果1: "+kk.ToString("#,0"));

            //小数値をカンマ編集
            double d = 45678.901;
            Console.WriteLine("結果2: "+d.ToString("#,0.####"));
            Console.WriteLine("結果3: "+d.ToString("#,0.0000"));

            Console.ReadKey();
        }
    }
}

実行結果
結果1: 1,234,567
結果2: 45,678.901
結果3: 45,678.9010

C#

Posted by arkgame