Format Specifier

noun

say it: “FOR-mat SPES-ih-fy-er” /ˈfɔːrmæt ˈspɛsɪfaɪər/

A short code after a colon, such as F2 or N0, that sets how a number or date is shown in a string.

What is Format Specifier in C#?

Format Specifier — A short code after a colon in an interpolated string that sets how a value is shown: F2 for two decimal places, N0 for thousands separators, C for currency and P for a percent.

decimal price = 1234.5m;
Console.WriteLine(quot;{price:F2}"); // 1234.50
Console.WriteLine(quot;{price:N0}"); // 1,235

In a sentence

  • “Adding the format specifier F2 made every price show two decimal places.”

Level: Apprentice · More C# terms at this level

Updated