1

Why doesn't this code work correctly? Do do I misunderstand something?

System.Console.WriteLine("{{{0:c}}}", 12323.09m);

Real output:

{c}

Expected output:

{$12,323.09}

Jeremy
  • 1
  • 85
  • 340
  • 366

2 Answers2

3

The issue is that {{{0:c}}} is parsed as {{ { ... }} }, and not as {{ { ... } }}.

Try

System.Console.WriteLine("{{{0:c}{1}", 12323.09m, '}');

Or see a similar sample in MSDN (see Escaping Braces):

int value = 6324;
string output = string.Format("{0}{1:D}{2}", 
                              "{", value, "}");
Console.WriteLine(output);
AlexD
  • 32,156
  • 3
  • 71
  • 65
0

Try this:

System.Console.WriteLine("{" + String.Format("{0:C}", 12323.09) + "}");

user700390
  • 2,287
  • 1
  • 19
  • 26