newbie queston on formatting console output

  • Thread starter Thread starter Jack Fu
  • Start date Start date
J

Jack Fu

How do I format output of strings, numbers, etc. on a console? For example,
the code below produces the console output shown below it. How do I specify
the output format? For example, if I enter 45.7 for money, how do I specify
that its output will look like $45.70? Thanks in advance!


Console.WriteLine("Item ID : {0}", Inventory[x].ID);
Console.WriteLine("Description : {0}", Inventory[x].description);
Console.WriteLine("Price : {0}", Inventory[x].price);


Item ID : 305
Description : wheel bearing
Price : 59.95
 
Jack,
How do I format output of strings, numbers, etc. on a console? For example,
the code below produces the console output shown below it. How do I specify
the output format? For example, if I enter 45.7 for money, how do I specify
that its output will look like $45.70? Thanks in advance!

Console.WriteLine("Price : {0:C}", Inventory[x].price);



Mattias
 
Mattias: Thanks! This is just what I needed.

Jack

Mattias Sjögren said:
Jack,
How do I format output of strings, numbers, etc. on a console? For example,
the code below produces the console output shown below it. How do I specify
the output format? For example, if I enter 45.7 for money, how do I specify
that its output will look like $45.70? Thanks in advance!

Console.WriteLine("Price : {0:C}", Inventory[x].price);



Mattias
 
Back
Top