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

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...