Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

label

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.

like image 917
Ricardo Deano Avatar asked Aug 11 '10 09:08

Ricardo Deano


People also ask

What is a thousand comma separator?

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.

How do you convert a decimal to a string?

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.


1 Answers

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

like image 171
James Manning Avatar answered Oct 14 '22 14:10

James Manning