Csharp數據格式初體驗
阿新 • • 發佈:2017-10-09
數據格式 Console.WriteLine();
/*{參數,占位符(多少個空格)}*/
Console.WriteLine("{0,6}\n+{1,5}\n-------\n{2,6}",i,j,i+j);
/*
i = 220
j = 25
220
+ 25
-------
245
*/
decimal m = 19.23m;
decimal n = 73.7m;
Console.WriteLine("我現在有{0,5:C2}",m);
Console.WriteLine("然後有{0,7:C2}",n);
Console.WriteLine("{0,8:C2}\n+\n{1,7:C2}\n----------\n{2,8:C2}\n",m,n,m+n);
Console.ReadLine();
}
}
}
/*
i = 220
j = 25
220
+ 25
-------
245
我現在有¥19.23
然後有 ¥73.70
¥19.23
+
¥73.70
----------
¥92.93
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 數字格式化
{
class Program
{
static void Main(string[] args)
{
int i = 220;
Console.WriteLine("i = {0}",i);
int j = 25;
Console.WriteLine("j = {0}",j);
/*{參數,占位符(多少個空格)}*/
Console.WriteLine("{0,6}\n+{1,5}\n-------\n{2,6}",i,j,i+j);
/*
i = 220
j = 25
220
+ 25
-------
245
*/
decimal m = 19.23m;
decimal n = 73.7m;
Console.WriteLine("然後有{0,7:C2}",n);
Console.WriteLine("{0,8:C2}\n+\n{1,7:C2}\n----------\n{2,8:C2}\n",m,n,m+n);
Console.ReadLine();
}
}
}
/*
i = 220
j = 25
220
+ 25
-------
245
我現在有¥19.23
然後有 ¥73.70
¥19.23
+
¥73.70
----------
*/
本文出自 “phize” 博客,請務必保留此出處http://12756301.blog.51cto.com/12746301/1970942
Csharp數據格式初體驗