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);

Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *