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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...