C# String Formatting for Money

February 20, 2023

Here are some different ways to handle money formatting in C#.

decimal amount = 12_123.456m;

// Composite formatting.
Console.WriteLine(String.Format("Amount #1: {0:0,0.00}", amount));

// Using string interpolation.
Console.WriteLine($"Amount #2: {amount:0,0.00}");
Console.WriteLine($"Amount #3: {amount:n2}");

// Currency format specifier "C" automatically adds dollar sign.
Console.WriteLine($"Amount #4: {amount:c2}");

Results:

Amount #1: 12,123.46
Amount #2: 12,123.46
Amount #3: 12,123.46
Amount #4: $12,123.46