C#的格式化輸出數字

來源:互聯網
上載者:User
 class Program    {        static void Main(string[] args)        {            Console.WriteLine("數字格式化輸出");            formateNumericalValue(99999);            Console.ReadKey();        }        /*         * 數字格式化輸出         * c或C  貨幣化格式,預設會使用電腦設定的國家和地區的貨幣符號表示         * e或E  科學計數法表示         * d或D  格式化十進位表示         * f或F  使用小數格式化輸出         * n或N  基本數值格式化(帶逗號)         * x或X  十六進位表示         * g或G  格式化為定點或指數表示         */        static void formateNumericalValue(Int32 nValue)        {            Console.WriteLine("格式化輸出{0}", nValue);            Console.WriteLine("c,貨幣化輸出:{0:c}", nValue);            Console.WriteLine("d9,格式化十進位輸出:{0:d9}", nValue);            Console.WriteLine("e,冪標記法{0:e}", nValue);            Console.WriteLine("f,小數標記法:{0:f3}", nValue);            Console.WriteLine("n,基本數值格式化:{0:n3}", nValue);            Console.WriteLine("x,16進位格式表示:{0:x}", nValue);            Console.WriteLine("g,定點或指數表示:{0:g}", nValue);            Console.WriteLine("g,定點或指數表示:{0:g1}", nValue);        }        /*         * out:        數字格式化輸出        格式化輸出99999        c,貨幣化輸出:¥99,999.00        d9,格式化十進位輸出:000099999        e,冪標記法9.999900e+004        f,小數標記法:99999.000        n,基本數值格式化:99,999.000        x,16進位格式表示:1869f        g,定點或指數表示:99999        g,定點或指數表示:1e+05         */    }

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.