Friday, January 7, 2011

C#: How to format a decimal to have thousand separator with current UI culture

See following example:
decimal sum = 120400600;
string sumText = sum.ToString("N0", Thread.CurrentThread.CurrentCulture.NumberFormat);

Output:
120,400,600


Here I have used the format "N0" as I don't need any decimal points. According to your requiremet you can use "N2", "N4", etc.

0 comments:

Post a Comment