New! GraphQL.NET Cookbook by Senthil Kumar Balu

C# Tips and Tricks #16 – Format number to display comma for thousands place

In this C# tips and tricks blog post , we look at how to use String.Format function to display the commas in the thousand’s place for a number in C#.

Assume that you have an integer 123456 and you would like to format it to display the comma as for the thousand’s seperator. You can use the string.format function and pass “N” for the format specifier (first) parameter as shown below.

string.Format(“{0:n}”, 123456);

This will display the output as 123,456.00

Incase you don’t want to display the decimal , you can pass the format specifier as N0 instead of N as shown below.

string.Format(“{0:n0}”, 123456);

Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.