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

Viewed 97233

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.

7 Answers

double.Parse(Amount).ToString("N");

Do not cast integral to double to do this!
Use NumberFormatInfo helper class, e.g:

    var nfi = new NumberFormatInfo() {
        NumberDecimalDigits = 0,
        NumberGroupSeparator = "."
    };

    var i = 1234567890;
    var s = i.ToString("N", nfi); // "1.234.567.890"
Related