0

This is my reference question; String.Format Same Code Different View

When i try this code;

var cultureWithoutCurrencySymbol =
        (CultureInfo)CultureInfo.CurrentCulture.Clone();
            cultureWithoutCurrencySymbol.NumberFormat.CurrencySymbol = "";
            GridView1.FooterRow.Cells[9].Text = String.Format(cultureWithoutCurrencySymbol, "{0:c}", sumMV).Trim();

I gettin an error like this;

enter image description here

How can i solve this problem? Is it something wrong in my code?

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • Can't see where `sumMV` is defined, and if it is assigned any value – Ron Harlev Apr 19 '11 at 06:24
  • @ron-harlev here http://i.imgur.com/ae1rs.png – Soner Gönül Apr 19 '11 at 06:30
  • @Soner How about using **{0:N}** – V4Vendetta Apr 19 '11 at 06:43
  • Why would you need Trim() there? can't you just remove that and try – Subhash Dike Apr 19 '11 at 06:44
  • @V4Vendetta {0:N} doesn't work. Sorry! – Soner Gönül Apr 19 '11 at 06:46
  • @Subhash Dike Look at my reference question. unfortunately i delete trim but still doesn't work. – Soner Gönül Apr 19 '11 at 06:49
  • @Soner: Can you widen the Name column in your Watch window? It seems as if cultureWithoutCurrencySymbol is contained three times in that list, but twice it is null and once it is not null. That's not possible, so please make the Name column wide enough, so we can see the whole name. Additionally: Did you check that the following are not null: (1) `GridView1` (2) `GridView1.FooterRow` (3) `GridView1.FooterRow.Cells` (4) `GridView1.FooterRow.Cells[9]`. BTW: The trim is necessary, otherwise there will be a space after the formated number. – Daniel Hilgarth Apr 19 '11 at 08:14

1 Answers1

0

Since you want currency without symbol why don't simply use:

sumVM.ToString()
Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75
  • Please see the linked question. It doesn't take into account the possible user specific settings for currencies. – Daniel Hilgarth Apr 19 '11 at 09:24
  • my point is don't format it as a currency because you just want a currency without a currency symbol => this mean a number only. So just format it as a number – Ahmed Magdy Apr 19 '11 at 09:45
  • Not a valid point in the following circumstance: The number indeed represents a currency and it is indicated elsewhere which currency. Formatting it as a normal number discards the user specific settings for currencies. – Daniel Hilgarth Apr 19 '11 at 10:17