How to insert a thousand separator (comma) with convert to double

Ricardo Deano picture Ricardo Deano · Aug 11, 2010 · Viewed 81.7k times · Source

I am trying to format the contents of a text box:

this.lblSearchResults1.Text =
    Convert.ToDouble(lblSearchResults1.Text).ToString(); 

How do I amend this so that I the text includes comma/thousand separators?

i.e. 1,000 instead of 1000.

Answer

James Manning picture James Manning · Aug 11, 2010

Looking at the standard numeric format strings:

You can most easily use 'N' which will do the right thing based on the user culture, so in your case you can just add "N" as a param to the ToString

([double]12345.67).ToString("N")

12,345.67