tags:

views:

49

answers:

5

Morning all

I'm being (a) thick and (b) blind.

I have the following, tiny bit of code:

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

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

i.e. 1,000 instead of 1000.

Apologies for the dumb question.

A: 

Use ... .ToString("#,##0.00") or variations thereof.

Henk Holterman
A: 

Looking at the standard numeric format strings:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

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

C:\ » ([double]12345.67).ToString("N")

12,345.67

James Manning
A: 

The easiest way to do it would be something like:

Convert.ToDouble("1234567.12345").ToString("N")

If you want to control the decimal places you can do something like:

Convert.ToDouble("1234567.12345").ToString("N3")

In general look at the overloads on ToString for more exciting possibilities.

Chris
A: 

If you take a closer look at Standard Numeric Format Strings you can try one of the following:

.ToString("n", CultureInfo.GetCultureInfo("en-US"))
.ToString("n", CultureInfo.GetCultureInfo("de-DE"))
.ToString("n", CultureInfo.CurrentCulture)
Oliver