Author : MD TAREQ HASSAN | Updated : 2021/03/22

Format Specifier

String Interpolation

// String interpolation
// C => Currency
var foo = 10;
$"amount: {foo:C}"  // amount of money is $10
$"amount: {foo:C2}" // amount of money is $10.00

ToString

// ToString()
var cost = 1632.54; 
cost.ToString("C", new System.Globalization.CultureInfo("en-US"))  // $1,632.54
cost.ToString("C", CultureInfo.CreateSpecificCulture("ja-JP")) // ¥1,632.54

// my CurrentCulture is ja-JP
cost.ToString("C", CultureInfo.CurrentCulture)  // ¥1,632.54
cost.ToString("C4", CultureInfo.CurrentCulture)  // ¥1,632.5400