Fungsi Terbilang Visual Basic .NET

 


Public Function ToTerbilang(ByVal x As Long) As String

        Dim abil() As String = {"", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas"}
        Dim s As String = ""
        If x < 12 Then
            s = " " & abil(x)
        ElseIf x < 20 Then
            s = ToTerbilang(x - 10) & " belas"
        ElseIf x < 100 Then
            s = ToTerbilang(x \ 10) & " puluh" & ToTerbilang(x Mod 10)
        ElseIf x < 200 Then
            s = " seratus" & ToTerbilang(x - 100)
        ElseIf x < 1000 Then
            s = ToTerbilang(x \ 100) & " ratus" & ToTerbilang(x Mod 100)
        ElseIf x < 2000 Then
            s = " seribu" & ToTerbilang(x - 1000)
        ElseIf x < 1000000 Then
            s = ToTerbilang(x \ 1000) & " ribu" & ToTerbilang(x Mod 1000)
        ElseIf x < 1000000000 Then
            s = ToTerbilang(x \ 1000000) & " juta" & ToTerbilang(x Mod 1000000)
        ElseIf x < 1000000000000.0# Then
            s = ToTerbilang(x \ 1000000000) & " miliar" & ToTerbilang(x Mod 1000000000)
        End If
        Return s

    End Function

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel