Reputation: 51
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}
Upvotes: 1
Views: 68
Reputation: 2339
Try this:
System.Console.WriteLine("{" + String.Format("{0:C}", 12323.09) + "}");
Upvotes: 0
Reputation: 32576
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);
Upvotes: 3