반응형

* VBNET 숫자 (금액) 을 한글로 변화 ...

 

메인화면

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        label1.Text = CalToHan(textBox1.Text)
    End Sub

    Private Function NumberHan(ByVal iTmp As Integer) As String
        Dim sTmp As String = ""

        Select Case iTmp
            Case 0
                sTmp = ""
            Case 1
                sTmp = "일"
            Case 2
                sTmp = "이"
            Case 3
                sTmp = "삼"
            Case 4
                sTmp = "사"
            Case 5
                sTmp = "오"
            Case 6
                sTmp = "육"
            Case 7
                sTmp = "칠"
            Case 8
                sTmp = "팔"
            Case 9
                sTmp = "구"
        End Select
        Return sTmp
    End Function


    Private Function NumberUnit(ByVal iTmp As Integer) As String

        Dim sTmp As String = ""
        Select Case iTmp
            Case 0
                sTmp = ""
            Case 1
                sTmp = ""
            Case 2
                sTmp = "십"
            Case 3
                sTmp = "백"
            Case 4
                sTmp = "천"
            Case 5
                sTmp = "만"
            Case 6
                sTmp = "십"
            Case 7
                sTmp = "백"
            Case 8
                sTmp = "천"
            Case 9
                sTmp = "억"
            Case 10
                sTmp = "십"
            Case 11
                sTmp = "백"
            Case 12
                sTmp = "천"
        End Select

        Return sTmp

    End Function

    Private Function CalToHan(ByVal strTmp As String) As String
        Dim iTotalLength As Integer = strTmp.Length
        Dim iLength As Integer = iTotalLength
        Dim cTmp() As Byte = System.Text.Encoding.ASCII.GetBytes(strTmp)
        Dim sTmp As String = ""

        Dim iCount As Integer
        For iCount = 0 To iTotalLength - 1 Step iCount + 1

            If cTmp(iCount) - 48 <> 0 Then
                sTmp += NumberHan(cTmp(iCount) - 48) + NumberUnit(iLength)
            End If
            iLength -= 1
        Next
        sTmp += "원"
        Return sTmp

    End Function


End Class

*예제 결과

 

 

반응형

+ Recent posts