0

I'm having an issue with my ListView. I want to display value as a currency, i.e

£150.02

Instead I get

£$150.02

Here is my code:

<GridViewColumn Header="Value" Width="80" DisplayMemberBinding="{Binding value, StringFormat=£{0:C}}" />
arti
  • 645
  • 1
  • 8
  • 27
  • 3
    `C` - output locale specific currency (which seems `$` in your case), and pound symbol is output as it is. Two options: change locale ([globally](http://stackoverflow.com/q/1265773/1997232)?) or output manually (e.g. output currency value as `decimal` with prefix you want). – Sinatr Nov 25 '15 at 13:04
  • is it an option in VS2015? My other projects written in VS2013 display data as they should – arti Nov 25 '15 at 13:12
  • @ati This has no changed since .NET 1.0. – Richard Nov 25 '15 at 13:55

2 Answers2

3

You need to change the Language of the control

this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);

You are having an Extra £ remove it,

<GridViewColumn Header="Value" Width="80" DisplayMemberBinding="{Binding value, StringFormat={}{0:C}}" />
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • now it displays ££150.02, when i set it to StringFormat={0:C} it shows no data isn't there an option in VS2015 to edit global value? – arti Nov 25 '15 at 13:12
  • Use `StringFormat={0:C}` in xaml (without pound symbol). – Sinatr Nov 25 '15 at 13:13
  • VS2015 is not allowing me. got 7 errors – arti Nov 25 '15 at 13:15
  • 3
    The XAML parser won't recognize the leading curly brace as the begin of a format string. Write `StringFormat={}{0:C}` to get around that. – Clemens Nov 25 '15 at 13:23
  • thanks clemens :) after long time :) – Sajeetharan Nov 25 '15 at 13:24
  • It shows $ not £. Is it an option within VS2015? As i said, my other projects in VS2013 work perfectly fine. My whole system is set to UK. And i don't want to put extra code on each of my UserControls to achieve it – arti Nov 25 '15 at 13:31
  • 1
    @arti: First of all it has nothing to do with VS2015. – Marshal Nov 25 '15 at 13:32
  • 2
    `XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name)` uses the current culture. If your system is in the US, it shows you a `$`, in UK it will show a pound symbol. Mine is german, and shows me a `€` symbol. And it's not only the symbol, but also the correct format, like `100,00 €` as opposed to `$100.00`. More details [here](https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx). – Clemens Nov 25 '15 at 13:34
  • 1
    so how can you explain fact, my system is set to UK and displays $ ? – arti Nov 25 '15 at 13:37
  • 2
    No idea. You can make it explicit by `Language = XmlLanguage.GetLanguage("en-GB");` – Clemens Nov 25 '15 at 13:40
  • 1
    @arti: did you check Region and Language > Additional Settings > Currency > Currency Symbol ? – Marshal Nov 25 '15 at 13:40
0

Just remove C then it should works:

DisplayMemberBinding="{Binding value, StringFormat=£{0}}"
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • it shows no data (empty field) – arti Nov 25 '15 at 13:18
  • @arti ... Don't remove `0` just remove `C`. It should works! – Salah Akbari Nov 25 '15 at 13:19
  • This is not a solution, it is a work around. Correct solution would be to make currency symbol automatically fetch it according to current culture – Marshal Nov 25 '15 at 13:35
  • 1
    it is solution, especially my app will be used in Czech Republic and they have to see it as a £ not their currency. All depends what do you want to achieve – arti Nov 25 '15 at 13:38
  • @arti: you can set the culture as en-Gb explicitly as clemens suggested. That would be a proper method to achive it. – Marshal Nov 25 '15 at 13:42