반응형

* C# 숫자(금액) 을 한글로 변환 하기 예제...

 

메인화면

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CSharp_숫자를한글로
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = CalToHan(textBox1.Text);
        }

        #region 숫자를 한글로 읽기 변환 ex) 1542500 => 일백오십사만이천오백원
        public  string CalToHan(string strTmp)
        {
            int iTotalLength = strTmp.Length;
            int iLength = iTotalLength;
            byte[] cTmp = Encoding.ASCII.GetBytes(strTmp);
            string sTmp = "";

            for (int iCount = 0; iCount < iTotalLength; iCount++)
            {
                if (cTmp[iCount] - 48 != 0)
                {
                    sTmp += NumberHan(cTmp[iCount] - 48) + NumberUnit(iLength);
                }
                iLength -= 1;
            }
            sTmp += "원";
            return sTmp;
        }
        private  string NumberUnit(int iTmp)
        {
            string sTmp = "";
            switch (iTmp)
            {
                case 0:
                    {
                        sTmp = "";
                        break;
                    }
                case 1:
                    {
                        sTmp = "";
                        break;
                    }
                case 2:
                    {
                        sTmp = "십";
                        break;
                    }
                case 3:
                    {
                        sTmp = "백";
                        break;
                    }
                case 4:
                    {
                        sTmp = "천";
                        break;
                    }
                case 5:
                    {
                        sTmp = "만";
                        break;
                    }
                case 6:
                    {
                        sTmp = "십";
                        break;
                    }
                case 7:
                    {
                        sTmp = "백";
                        break;
                    }
                case 8:
                    {
                        sTmp = "천";
                        break;
                    }
                case 9:
                    {
                        sTmp = "억";
                        break;
                    }
                case 10:
                    {
                        sTmp = "십";
                        break;
                    }
                case 11:
                    {
                        sTmp = "백";
                        break;
                    }
                case 12:
                    {
                        sTmp = "천";
                        break;
                    }
            }
            return sTmp;
        }
        private  string NumberHan(int iTmp)
        {
            string sTmp = "";

            switch (iTmp)
            {
                case 0:
                    {
                        sTmp = "";
                        break;
                    }
                case 1:
                    {
                        sTmp = "일";
                        break;
                    }
                case 2:
                    {
                        sTmp = "이";
                        break;
                    }
                case 3:
                    {
                        sTmp = "삼";
                        break;
                    }
                case 4:
                    {
                        sTmp = "사";
                        break;
                    }
                case 5:
                    {
                        sTmp = "오";
                        break;
                    }
                case 6:
                    {
                        sTmp = "육";
                        break;
                    }
                case 7:
                    {
                        sTmp = "칠";
                        break;
                    }
                case 8:
                    {
                        sTmp = "팔";
                        break;
                    }
                case 9:
                    {
                        sTmp = "구";
                        break;
                    }
            }
            return sTmp;
        }
        #endregion

    }
}

 

-> Ascii 코드 값 숫자 0 -> 48 , 1->49 ~ 

 

 

*예제 결과

반응형

+ Recent posts