C#| 使用String.Format()方法将浮点数的左填充(左对齐)与空格
为了使浮点数与空格对齐,我们可以在C#中使用,这是示例。String.Format()
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Demo for space alignment in floating point number");
Console.WriteLine(String.Format("{0,10:0.0}", 512.4567));
Console.WriteLine(String.Format("{0,-10:0.0}", 512.4567));
Console.WriteLine(String.Format("{0,10:0.0}", -512.4567));
Console.WriteLine(String.Format("{0,-10:0.0}", -512.4567));
Console.WriteLine();
}
}
}输出结果
Demo for space alignment in floating point number
512.5
512.5
-512.5
-512.5热门推荐
10 新年的生日祝福语简短
11 哥哥新婚祝福语创意简短
12 升职祝福语朋友简短精辟
13 拜新年的祝福语简短
14 年底老板祝福语简短的
15 新年送老师简短祝福语
16 中班入学祝福语简短大全
17 祝贺新店开业祝福语简短
18 18岁的祝福语简短