Are you sure this takes into account the current system locale, i.e. displaying , when it should and . when it should?
Main Topics
Browse All TopicsLet's say I have the integer (or better yet, long) 1000000. How can I convert it properly to a string with thousand separators?
On systems where comma is the thousand separator the outcome should be "1,000,000" and on systems where dot is the thousand separator the outcome should be "1.000.000".
I have tried doing String.Format("{0:n}", 1000000); but this just keeps giving me "1.000.000,00" which is not what I want (I don't want the decimal point there at the end, because I am dealing with integers and not doubles).
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yes, it takes system locale into account. As for an explanation why it works like this... It's custom number formatting. A quick google turns up this page:
http://blog.stevex.net/ind
Have a look at the chapter 'Numbers', specifically 'Custom number formatting'.
I still find this a mystery. That SteveX guy has a nice website there, but he still leaves me in the dark. For instance, why does the format string "#,0" also seem to work fine in this case? I guess I know theoretically from that website what # represents, what "," represents and what 0 represents, but I don't know how to put all them together and understand the result.
I have increased the points of this question to 300.
will be easier to use "N"
long x = 123456789;
string s = x.ToString("N");
or
string s = string.Format("{0:N}", x);
also, you can put specific culture information:
s = x.ToString("N", CultureInfo.InvariantCultu
s = x.ToString("N", CultureInfo.CreateSpecific
also you can specify decimals, as:
s = x.ToString("N2"); // will show 2 decimal digits
I found the "N" solution to be the simplest to understand. In my case therefore I ended up using simply "N0" (N zero). So thanks for this advice and all the other advices.
Just out of curiosity though, what comments were said that were deleted? I didn't get a chance to see them before they got removed.
dedekind,
You asked "For instance, why does the format string "#,0" also seem to work fine in this case?"
The answer is in the documentation.
http://msdn.microsoft.com/
The ',' character serves as both a thousand separator specifier and a number scaling specifier.
Thousand separator specifier: If one or more ',' characters is specified between two digit placeholders (0 or #) that format the integral digits of a number, a group separator character is inserted between each number group in the integral part of the output.
Business Accounts
Answer for Membership
by: NeoTeqPosted on 2008-06-20 at 10:10:45ID: 21833065
This does what you are looking for.
Select allOpen in new window