《零基础学C#》第六章-实例03:格式化输出数值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wtxhai/article/details/88636284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Example603
{
    class Program
    {
        static void Main(string[] args)
        {
            //输出金额
            Console.WriteLine(string.Format("1251+3950的结果是(以货币形式显示):{0:C}", 1251 + 3950));
            //用科学计数法表示
            Console.WriteLine(string.Format("120000.1用科学计数法表示:{0:E}",120000.1));
            //用分隔符显示数字
            Console.WriteLine(string.Format("12800以分隔符数字显示的结果是:{0:N0}",12800));
            //输出小数点后两位
            Console.WriteLine(string.Format("π取两位小数点:{0:F2}", Math.PI));
            //输出16进制数
            Console.WriteLine(string.Format("33的16进制结果是:{0:X4}", 33));
            //输出百分号数值
            Console.WriteLine(string.Format("天才是由{0:P0}的灵感,加上{1:P0}的汗水", 0.01, 0.99));
            Console.ReadLine();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wtxhai/article/details/88636284