In a programme:

Decimal a = 7m; Console.WriteLine("{0:C}", a); 

Conclusion: 7.00?

Without a currency sign and with a question mark at the end. What need to do?

  • and in my example, this example does not compile at all - Grundy

1 answer 1

First, in the error code, it will be correct to do the output like this:

  Console.WriteLine("{0:C}", a); 

Not there were braces.

And secondly, for the rest - everything is true, it should be so. Namely: you specify a variable of the monetary type decimal a = 7m , which should be displayed with a currency sign. What kind of currency sign will be used - is taken from the regional settings of the system. In the case of the Russian regional settings, this will be the ruble, and the currency sign, which should be issued - $.

But you have here output to the console, which, in turn, uses to display the font, which does not have this character, and therefore displays a question mark instead.

UPD: Under Win 7, the following code displays everything correctly:

  decimal a = 7m; var s = string.Format("{0:C}", a); MessageBox.Show(s); 

enter image description here

  • one
    that's right, it should be. - Without a currency sign and with a question mark at the end ? - Grundy
  • Updated the answer. In this context, the question is the currency sign. - BlackWitcher
  • @BlackWitcher, Thanks for the reply. In real code, quotes are correct. This I HERE made a mistake by inexperience - BuilderC
  • Changed the settings on the dollar, and everything turned out. Thanks again. - BuilderC 2:51 pm
  • You are welcome! Glad my answer was helpful. - BlackWitcher