HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

.NET String.Format() to add commas in thousands place for a number

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
netforaddcommasnumberformatstringplacethousands

Problem

I want to add a comma in the thousands place for a number.

Would String.Format() be the correct path to take? What format would I use?

Solution

$"{1234:n}";  // Output: 1,234.00
$"{9876:n0}"; // No digits after the decimal point. Output: 9,876

Code Snippets

$"{1234:n}";  // Output: 1,234.00
$"{9876:n0}"; // No digits after the decimal point. Output: 9,876

Context

Stack Overflow Q#105770, score: 1569

Revisions (0)

No revisions yet.