Author : MD TAREQ HASSAN | Updated : 2021/03/22
Format Specifier
- The Currency (“C”) Format Specifier
- The Decimal (“D”) Format Specifier
- The Exponential (“E”) Format Specifier
- The Fixed-Point (“F”) Format Specifier
- The General (“G”) Format Specifier
- The Numeric (“N”) Format Specifier
- The Percent (“P”) Format Specifier
- The Round-trip (“R”) Format Specifier
- The Hexadecimal (“X”) 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