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.
The character used as the thousands separator In the United States, this character is a comma (,). In Germany, it is a period (.). Thus one thousand and twenty-five is displayed as 1,025 in the United States and 1.025 in Germany. In Sweden, the thousands separator is a space.
To convert a Decimal value to its string representation using a specified culture and a specific format string, call the Decimal. ToString(String, IFormatProvider) method.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With