Long-Slow-Distance

Programming Notes with Unity

メニュー

[C#] 数値を3ケタ毎にカンマ区切りした文字列を作成する

世界基準なのかは詳しくは知らないが、数値を3ケタ区切りのカンマ付きで表示する事が多々あるので汎用化。
書式指定子にそれ用の便利なものがあるのでそれを使うだけ。ありがとうC#…

	//--------------------------------------------------------------------------------
	// 数値を3ケタ毎にカンマ区切りした文字列にして返す
	//--------------------------------------------------------------------------------
	public static string		Get3DigitFormatStr( int val ){
		return string.Format( "{0:#,0}", val );
	}

参考:
http://www.atmarkit.co.jp/fdotnet/dotnettips/620number3groupsep/number3groupsep.html
http://www.ipentec.com/document/document.aspx?page=csharp-format-comma-separated-every-three-digits

関連記事