Class Number to Word

Class untuk konversi angka menjadi huruf (english/indonesia) dengan menggunakan VB.Net


Public Class ClassNumToWord

'Up To 999,999,999,999,999

'English
Private sPWord1Digit_Eng As String = "| ONE| TWO| THREE| FOUR| FIVE| SIX| SEVEN| EIGHT| NINE"
Private sPWord2DigitFrom10To19_Eng As String = "| TEN| ELEVEN| TWELVE| THIRTEEN| FOURTEEN| FIFTEEN | SIXTEEN| SEVENTEEN| EIGHTEEN| NINETEEN"
Private sPWord2DigitFrom20To99_Eng As String = "|| TWENTY| THIRTY| FOURTY| FIFTY| SIXTY| SEVENTY| EIGHTY| NINETY"

'Indonesian
Private sPWordFrom1To11_Ind As String = "| SATU| DUA| TIGA| EMPAT| LIMA| ENAM| TUJUH| DELAPAN| SEMBILAN"

Public Function Wording(ByVal sValue As String) As String

Dim result As String = ""
Dim iValue As Int64 = Convert.ToInt64(sValue)

If iValue > 999999999999999 Then

result = "OVERFLOW"

Else

Dim aPWord1Digit_Eng() As String = sPWord1Digit_Eng.Split("|")

If iValue >= 0 And iValue <= 9 Then

result = aPWord1Digit_Eng(iValue).ToString

ElseIf iValue > 9 And iValue <= 99 Then

result = sWord2Digit(sValue)

ElseIf iValue > 99 And iValue <= 999 Then

result = sWord3Digit(sValue)

ElseIf iValue > 999 And iValue <= 9999 Then

Dim sValue3Digit As String = Mid(sValue, 2, 3)

result = aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " THOUSAND" & _
IIf(sValue3Digit = "000", "", sWord3Digit(sValue3Digit))

ElseIf iValue > 9999 And iValue <= 99999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit As String = Mid(sValue, 3, 3)

result = sWord2Digit(sValue2Digit) & " THOUSAND" & _
IIf(sValue3Digit = "000", "", sWord3Digit(sValue3Digit))

ElseIf iValue > 99999 And iValue <= 999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)

result = sWord3Digit(sValue3Digit1) & " THOUSAND" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2))

ElseIf iValue > 999999 And iValue <= 9999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)

result = aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " MILLION" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1) & " THOUSAND") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2))

ElseIf iValue > 9999999 And iValue <= 99999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)

result = sWord2Digit(sValue2Digit) & " MILLION" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1) & " THOUSAND") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2))

ElseIf iValue > 99999999 And iValue <= 999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)

result = sWord3Digit(sValue3Digit1) & " MILLION" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " THOUSAND") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3))

ElseIf iValue > 999999999 And iValue <= 9999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)
Dim sValue3Digit3 As String = Mid(sValue, 8, 3)

result = aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " BILLION" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " MILLION") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " THOUSAND") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3))

ElseIf iValue > 9999999999 And iValue <= 99999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)
Dim sValue3Digit3 As String = Mid(sValue, 9, 3)

result = sWord2Digit(sValue2Digit) & " BILLION" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " MILLION") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " THOUSAND") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3))

ElseIf iValue > 99999999999 And iValue <= 999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)
Dim sValue3Digit4 As String = Mid(sValue, 10, 3)

result = sWord3Digit(sValue3Digit1) & " BILLION" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " MILLION") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3) & " THOUSAND") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4))

ElseIf iValue > 999999999999 And iValue <= 9999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)
Dim sValue3Digit3 As String = Mid(sValue, 8, 3)
Dim sValue3Digit4 As String = Mid(sValue, 11, 3)

result = aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " TRILLION" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1) & " BILLION") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " MILLION") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3) & " THOUSAND") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4))

ElseIf iValue > 9999999999999 And iValue <= 99999999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)
Dim sValue3Digit3 As String = Mid(sValue, 9, 3)
Dim sValue3Digit4 As String = Mid(sValue, 12, 3)

result = sWord2Digit(sValue2Digit) & " TRILLION" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1) & " BILLION") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " MILLION") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3) & " THOUSAND") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4))

ElseIf iValue > 99999999999999 And iValue <= 999999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)
Dim sValue3Digit4 As String = Mid(sValue, 10, 3)
Dim sValue3Digit5 As String = Mid(sValue, 13, 3)

result = sWord3Digit(sValue3Digit1) & " TRILLION" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2) & " BILLION") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3) & " MILLION") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4) & " THOUSAND") & _
IIf(sValue3Digit5 = "000", "", sWord3Digit(sValue3Digit5))

End If

End If

Return result

End Function

Public Function Wording(ByVal sValue As String, ByVal bIndonesian As Boolean) As String

Dim result As String = ""

If bIndonesian = False Then

result = Wording(sValue)

Else

Dim iValue As Int64 = Convert.ToInt64(sValue)

If iValue > 999999999999999 Then

result = "OVERFLOW"

Else

Dim aPWordFrom1To11_Ind() As String = sPWordFrom1To11_Ind.Split("|")

If iValue >= 0 And iValue <= 9 Then

result = aPWordFrom1To11_Ind(iValue).ToString

ElseIf iValue > 9 And iValue <= 99 Then

result = sWord2Digit(sValue, True)

ElseIf iValue > 99 And iValue <= 999 Then

result = sWord3Digit(sValue, True)

ElseIf iValue > 999 And iValue <= 9999 Then

result = sWord4Digit(sValue)

ElseIf iValue > 9999 And iValue <= 99999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit As String = Mid(sValue, 3, 3)

result = sWord2Digit(sValue2Digit, True) & " RIBU" & _
IIf(sValue3Digit = "000", "", sWord3Digit(sValue3Digit, True))

ElseIf iValue > 99999 And iValue <= 999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)

result = sWord3Digit(sValue3Digit1, True) & " RIBU" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True))

ElseIf iValue > 999999 And iValue <= 9999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)


result = aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " JUTA" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1, True) & " RIBU") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True))

ElseIf iValue > 9999999 And iValue <= 99999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)

result = sWord2Digit(sValue2Digit, True) & " JUTA" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1, True) & " RIBU") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True))

ElseIf iValue > 99999999 And iValue <= 999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)

result = sWord3Digit(sValue3Digit1, True) & " JUTA" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " RIBU") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True))

ElseIf iValue > 999999999 And iValue <= 9999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)
Dim sValue3Digit3 As String = Mid(sValue, 8, 3)

result = aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " MILIYAR" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " JUTA") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " RIBU") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True))

ElseIf iValue > 9999999999 And iValue <= 99999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)
Dim sValue3Digit3 As String = Mid(sValue, 9, 3)

result = sWord2Digit(sValue2Digit, True) & " MILIYAR" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " JUTA") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " RIBU") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True))

ElseIf iValue > 99999999999 And iValue <= 999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)
Dim sValue3Digit4 As String = Mid(sValue, 10, 3)

result = sWord3Digit(sValue3Digit1, True) & " MILIYAR" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " JUTA") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True) & " RIBU") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4, True))

ElseIf iValue > 999999999999 And iValue <= 9999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 2, 3)
Dim sValue3Digit2 As String = Mid(sValue, 5, 3)
Dim sValue3Digit3 As String = Mid(sValue, 8, 3)
Dim sValue3Digit4 As String = Mid(sValue, 11, 3)

result = aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & " TRILIYUN" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1, True) & " MILIYAR") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " JUTA") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True) & " RIBU") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4, True))

ElseIf iValue > 9999999999999 And iValue <= 99999999999999 Then

Dim sValue2Digit As String = Mid(sValue, 1, 2)
Dim sValue3Digit1 As String = Mid(sValue, 3, 3)
Dim sValue3Digit2 As String = Mid(sValue, 6, 3)
Dim sValue3Digit3 As String = Mid(sValue, 9, 3)
Dim sValue3Digit4 As String = Mid(sValue, 12, 3)

result = sWord2Digit(sValue2Digit, True) & " TRILIYUN" & _
IIf(sValue3Digit1 = "000", "", sWord3Digit(sValue3Digit1, True) & " MILIYAR") & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " JUTA") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True) & " RIBU") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4, True))

ElseIf iValue > 99999999999999 And iValue <= 999999999999999 Then

Dim sValue3Digit1 As String = Mid(sValue, 1, 3)
Dim sValue3Digit2 As String = Mid(sValue, 4, 3)
Dim sValue3Digit3 As String = Mid(sValue, 7, 3)
Dim sValue3Digit4 As String = Mid(sValue, 10, 3)
Dim sValue3Digit5 As String = Mid(sValue, 13, 3)

result = sWord3Digit(sValue3Digit1, True) & " TRILIYUN" & _
IIf(sValue3Digit2 = "000", "", sWord3Digit(sValue3Digit2, True) & " MILIYAR") & _
IIf(sValue3Digit3 = "000", "", sWord3Digit(sValue3Digit3, True) & " JUTA") & _
IIf(sValue3Digit4 = "000", "", sWord3Digit(sValue3Digit4, True) & " RIBU") & _
IIf(sValue3Digit5 = "000", "", sWord3Digit(sValue3Digit5, True))


End If

End If

End If

Return result

End Function

Private Function sWord3Digit(ByVal sValue As String) As String

Dim result As String = ""
Dim aPWord1Digit_Eng() As String = sPWord1Digit_Eng.Split("|")
Dim sValueLast2Digit As String = Mid(sValue, 2, 2)

result = aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & _
IIf(Mid(sValue, 1, 2) = "00" Or Mid(sValue, 1, 1) = "0", "", " HUNDRED") & _
sWord2Digit(sValueLast2Digit)

Return result

End Function

Private Function sWord2Digit(ByVal sValue As String) As String

Dim result As String = ""
Dim aPWord1Digit_Eng() As String = sPWord1Digit_Eng.Split("|")
Dim iValue As Int64 = Convert.ToInt64(sValue)

If iValue > 9 And iValue <= 19 Then

Dim aPWord2Digit10To19_Eng() As String = sPWord2DigitFrom10To19_Eng.Split("|")
result = aPWord2Digit10To19_Eng(iValue - 9).ToString

Else

Dim aPWord2Digit20To99_Eng() As String = sPWord2DigitFrom20To99_Eng.Split("|")
result = aPWord2Digit20To99_Eng(Convert.ToInt16(Mid(sValue, 1, 1))).ToString & _
aPWord1Digit_Eng(Convert.ToInt16(Mid(sValue, 2, 1))).ToString

End If

Return result

End Function


Private Function sWord2Digit(ByVal sValue As String, ByVal bIndonesian As Boolean) As String

Dim result As String = ""

If bIndonesian = True Then

Dim aPWordFrom1To11_Ind() As String = sPWordFrom1To11_Ind.Split("|")
Dim iValue As Int64 = Convert.ToInt64(sValue)

If iValue = 10 Then

result = " SEPULUH"

ElseIf iValue = 11 Then

result = " SEBELAS"

ElseIf iValue > 11 And iValue <= 19 Then

result = aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 2, 1))) & " BELAS"

Else

result = aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 1, 1))) & _
IIf(Mid(sValue, 1, 1) = "0", "", " PULUH") & _
aPWordFrom1To11_Ind(Convert.ToInt16(Mid(sValue, 2, 1)))

End If

End If

Return result

End Function

Private Function sWord3Digit(ByVal sValue As String, ByVal bIndonesian As Boolean) As String

Dim result As String = ""

If bIndonesian = True Then

Dim aPWordFrom1To11_Ind() As String = sPWordFrom1To11_Ind.Split("|")
Dim sValueFirstDigit As String = Mid(sValue, 1, 1)
Dim sValueLast2Digit As String = Mid(sValue, 2, 2)

If sValueFirstDigit = "1" Then

result = " SERATUS" & sWord2Digit(sValueLast2Digit, True)

Else

Dim iValueFirstDigit As Int16 = Convert.ToInt16(sValueFirstDigit)

result = aPWordFrom1To11_Ind(iValueFirstDigit) & _
IIf(Mid(sValue, 1, 2) = "00" Or Mid(sValue, 1, 1) = "0", "", " RATUS") & _
sWord2Digit(sValueLast2Digit, True)

End If

End If

Return result

End Function

Private Function sWord4Digit(ByVal sValue As String) As String

Dim result As String = ""
Dim aPWordFrom1To11_Ind() As String = sPWordFrom1To11_Ind.Split("|")
Dim sValueFirstDigit As String = Mid(sValue, 1, 1)
Dim sValueLast3Digit As String = Mid(sValue, 2, 3)

If sValueFirstDigit = "1" Then

result = " SERIBU" & sWord3Digit(sValueLast3Digit, True)

Else

Dim iValueFirstDigit As Int16 = Convert.ToInt16(sValueFirstDigit)

result = aPWordFrom1To11_Ind(iValueFirstDigit) & _
IIf(Mid(sValue, 1, 3) = "000" Or Mid(sValue, 1, 2) = "00" Or Mid(sValue, 1, 1) = "0", "", " RIBU") & _
sWord3Digit(sValueLast3Digit, True)

End If

Return result

End Function


End Class

Figata Online © 2008. Template by Dicas Blogger.

TOPO