Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

hi I'm a beginner in C sharp, so hope you can help with this.
how to print double/float format,using

Console.WriteLine(" ###.### ", avg);

avg is of type float.
how to get digits after the decimal point?

thx
yuda
Posted
Updated 7-Dec-09 21:35pm
v2

Use String.Format.

For example :
Console.WriteLine(String.Format(”{0:(###) ###-####}”, 8005551212));

This will output
(800) 555-1212
http://www.csharp-examples.net/string-format-double/[^]

Hope this help you.

Cheers.
:rose:
 
Share this answer
 
When specifying a format for numbers the # sign means "Show number if its present" whereas a 0 character means "show the caracter always, including if its zero".

So I thin you want something like:

Console.WriteLine(" ###.0# ", avg); 


Which will show one decimal place always, and any additional decimal places if they are present.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900