「C#」ToString()で数値を文字列に変換する方法
構文
public string ToString (string? format);
format で指定された、このインスタンスの値の文字列形式。
C#コード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace com.arkgame.study.StringDemo
{
class Program
{
static void Main(string[] args)
{
int cftA = 5678;
double cost = 36.56789;
string cftB = cftA.ToString();
string cftC = cost.ToString("#.###");
Console.WriteLine("int値:"+cftB);
Console.WriteLine("double値:"+cftC);
}
}
}
実行結果
int値:5678
double値:36.568