using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 12345;

            //C, D, N, F, E, X 등 뒤에 숫자는 표현할 자리를 의미합니다.

            //아래식은 모두 ToString() 형태에서 사용 가능합니다!
            //Console.WriteLine("12345 C5 = {0}", a.ToString("C5"));

            Console.WriteLine("12345 C5 = {0:C5}", a); //통화
            Console.WriteLine("12345 D5 = {0:D5}", a); //정수 (0으로 채워집니다.)
            Console.WriteLine("12345 N5 = {0:N5}", a); //3자리마다 콤마
            Console.WriteLine("12345 F5 = {0:F5}", a); //실수형 (자릿수에서 반올림)
            Console.WriteLine("12345 E5 = {0:E5}", a); //지수형
            Console.WriteLine("12345 X5 = {0:X5}", a); //16진수

            Console.WriteLine();
            Console.WriteLine("12345 2진수  = {0}", Convert.ToString(a, 2));
            Console.WriteLine("12345 8진수  = {0}", Convert.ToString(a, 8));
            Console.WriteLine("12345 16진수 = {0}", Convert.ToString(a, 16));

            Console.WriteLine();
            DateTime dateTime = DateTime.Now;
            Console.WriteLine("DateTime.ToString(yyyy-MM-dd hh-mm-ss) = {0}", dateTime.ToString("yyyy-MM-dd hh-mm-ss"));

            Console.WriteLine();
            float b = 1234.5678f;
            Console.WriteLine("1234.5678f F2 = {0:F2}", b);
        }
    }
}

 

결과값

+ Recent posts