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


Question

I want to add a comma in the thousands place for a number. String.Format()?

1
771
12/18/2015 11:54:55 AM

Accepted Answer

String.Format("{0:n}", 1234);  // Output: 1,234.00
String.Format("{0:n0}", 9876); // No digits after the decimal point. Output: 9,876
1111
11/7/2018 12:30:22 AM

I found this to be the simplest way:

myInteger.ToString("N0")

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon