newbie queston on formatting console output

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
 
M

Mattias Sjögren

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
 
J

Jack Fu

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top