如何打印双精度/浮点格式 [英] how to print double/float format
本文介绍了如何打印双精度/浮点格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
您好,我是C Sharp的初学者,因此希望您能对此有所帮助.
如何使用
打印double/float格式
Console.WriteLine("###.###",avg);
平均类型为float.
如何获取小数点后的数字?
thx
yuda
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
推荐答案
使用String.Format
.
例如:
Console.WriteLine(String.Format({0:(###) ###-####}, 8005551212));
这将输出
(800)555-1212
http://www.csharp-examples.net/string-format-double/ [ ^ ]
希望这对您有所帮助.
干杯.
:rose:
UseString.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:
在为数字指定格式时,#号表示如果存在则显示数字",而0字符则表示始终显示字符,包括其零". />
所以我想你要这样的东西:
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.
这篇关于如何打印双精度/浮点格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文