2

I am new to c# and I am using windows forms.

Anyone knows how can I show currency symbol in a label. for example:

double test = 2.5;
lable1.text = test.Tostring();  

The result will show 2.5 but I want to show it as £2.5

Please help me how to do that. Thank you

Kate
  • 935
  • 4
  • 14
  • 34

2 Answers2

5

String.Format("{0:C}",test); or test.ToString("C"); should do the trick...

Neil Hibbert
  • 852
  • 5
  • 10
  • 1
    Yes, good call; string formatting is culture specific; make sure you are using en-GB (which I guess you will be if you are looking for the pound Stirling symbol). Just be careful if you deploy to servers hosted outside the UK that have a different default... – Neil Hibbert Mar 17 '16 at 19:49
1

Use string formats like this:

double test = 2.5;
lable1.text = test.ToString("£#.#")

Just in case you want to display the decimals upto 2 places, you could use something like:

lable1.text = test.ToString("£#.##")
Fᴀʀʜᴀɴ Aɴᴀᴍ
  • 6,131
  • 5
  • 31
  • 52