conversi hurup ke

gilfa

New member
Bagaimana cara mengkonversi hurup ke angka yang ada di raport kelas, seperti 85,56 menjadi Delapan puluh Lima koma Lima enam?
 
Bls: conversi hurup ke

Fungsi terbilang tuk SQL server
cucok buat VB (listing buat keuangan ada "rupiah"nya)

Code:
CREATE FUNCTION [DBO].[TerbilangDetil] (@Nilai as decimal) 
RETURNS varchar(200) AS 
BEGIN
declare @TS varchar(200), @ST varchar(200), @S integer, @p integer, @r1 integer, @Bil varchar(200), @TP varchar(200), @hasil varchar(200)
    set @ST = Right(rTrim(Str(@Nilai + 1000)), 3)
    set @S = cast(Right(@ST, 1) as integer)
    set @p = cast(substring(@ST, 2, 1) as integer)
    set @r1 = cast(Left(@ST, 1) as integer)
    set @Bil = ‘Satu    Dua     Tiga    Empat   Lima    ‘
    set @Bil = @Bil + ‘Enam    Tujuh   Delapan Sembilan’
   
    If @S = 0
        set @TS = ”
    Else
        set @TS = rTrim(substring(@Bil, @S * 8 - 7, 8)) + ‘ ‘
       
    If @p = 0
        set @TP = @TS
    Else
        If @p = 1
            If @S = 0
                set @TP = ‘Sepuluh ‘
            Else
                If @S = 1
                    set @TP = ‘Sebelas ‘
                Else
                    set @TP = rTrim(substring(@Bil, @S * 8 - 7, 8)) + ‘ Belas ‘
        Else
            set @TP = rTrim(substring(@Bil, @p * 8 - 7, 8)) + ‘ Puluh ‘ + @TS
       
    If @r1 = 0
        set @hasil = @TP
    Else
        If @r1 = 1
            set @hasil = ‘Seratus ‘ + @TP
        Else
            set @hasil = rTrim(substring(@Bil, @r1 * 8 - 7, 8)) + ‘ Ratus ‘ + @TP
return @hasil
END

CREATE FUNCTION [dbo].[terbilang] (@angka as decimal(19,2)) 
RETURNS varchar (200) AS 
BEGIN
Declare @b Decimal, @r Decimal, @J Decimal, @M Decimal, @T1 Decimal, @koma1 Decimal, @koma2 Integer, @hasil varchar(200)
Declare @s_t varchar(200), @ribu varchar(200), @Juta varchar(200), @Miliar varchar(200), @tx varchar(200), @angka1 varchar(200), @tx1 varchar(200)
set @s_t = case when Len(rTrim(cast(cast(@Angka as bigint) as varchar(20)))) < 15
        then replicate(’0′,15 - Len(rTrim(cast(cast(@Angka as bigint) as varchar(20))))) + rTrim(cast(cast(@Angka as bigint) as varchar(20)))
        else rTrim(cast(cast(@Angka as bigint) as varchar(20)))
         end
–set @z = cast(15 - Len(rTrim(cast(cast(@Angka as integer) as varchar(20)))) as varchar(20))
–+ rTrim(cast(cast(@Angka as integer) as varchar(20)))
set @r = cast(Right(@s_t, 3) as integer)
set @b = cast(substring(@s_t, 10, 3)  as integer)
set @J = cast(substring(@s_t, 7, 3)  as integer)
set @M = cast(substring(@s_t, 4, 3)  as integer)
set @T1 = cast(Left(@s_t, 3)  as integer)
set @ribu = case when @b = 0 then ‘ ‘ else case when @b = 1 then ‘Seribu’ else [dbo].TerbilangDetil(@b) + ‘Ribu’ end end
set @Juta = case when @J = 0 then ‘ ‘ else [dbo].TerbilangDetil(@J) + ‘Juta ‘ end
set @Miliar = case when @M = 0 then ‘ ‘ else [dbo].TerbilangDetil(@M) + ‘Miliar’ end
set @tx = Case
    when @Angka < 1000 –&& Ratusan
                then [dbo].TerbilangDetil(@r)
        when @Angka < 1000000 –&& Ribuan
                then @ribu + ‘ ‘ + [dbo].TerbilangDetil(@r)
        when @Angka < 1000000000 –&& Jutaan
                then [dbo].TerbilangDetil(@J) + ” + rTrim(’Juta ‘ + @ribu) + ‘ ‘ + [dbo].TerbilangDetil(@r)
    when @Angka < 1000000000000 –&& Miliaran
                then [dbo].TerbilangDetil(@M) + ” + rTrim(’Miliar ‘ + @Juta + @ribu) + ‘ ‘ + [dbo].TerbilangDetil(@r)
        when @Angka >= 1000000000000 –&& Trilliun
                then [dbo].TerbilangDetil(@T1) + ” + rTrim(’Trilliun ‘ + @Miliar + @Juta + @ribu) + ‘ ‘ + [dbo].TerbilangDetil(@r)
End
set @angka1 = rTrim(cast(@Angka as varchar(20)))
set @koma1 = case when charindex(’.', @angka1) = 0 then 0 else cast(rTrim(substring(@angka1, charindex(’.',@angka1) + 1, 2)) as integer) end
set @koma2 = Len(case when charindex(’.',@angka1) = 0 then ‘0′ else rTrim(substring(@angka1, charindex(’.',@angka1) + 1, 2)) end)
If @koma1 > 0
begin
    If @koma1 < 10 And @koma2 = 1
    set @koma1 = @koma1 * 10
    set @tx1 = [dbo].TerbilangDetil(@koma1)
    set @hasil = @tx + ‘Rupiah ‘ + @tx1 + ‘Sen’
end
Else
    set @hasil = @tx + ‘Rupiah’
return (@hasil)
END

Fungsi terbilang tuk exel ma acces (masih dengan "rupiah"nya)
taruh aja di macro
guna in nya ckup ketikkan =Terbilang([angka]), ganti [angka] dengan sel (excel) atau textbox(access).

Code:
Public Function Terbilang(x As Currency)
Dim triliun As Currency
Dim milyar As Currency
Dim juta As Currency
Dim ribu As Currency
Dim satu As Currency
Dim sen As Currency
Dim baca As String
If x > 1000000000000# Then
Terbilang = "<>"
Exit Function
End If
'Jika x adalah 0, maka dibaca sebagai 0
If x = 0 Then
baca = angka(0, 1)
Else
'Pisah masing-masing bagian untuk triliun, milyar, juta, ribu, rupiah, dan sen
triliun = Int(x * 0.001 ^ 4)
milyar = Int((x - triliun * 1000 ^ 4) * 0.001 ^ 3)
juta = Int((x - triliun * 1000 ^ 4 - milyar * 1000 ^ 3) / 1000 ^ 2)
ribu = Int((x - triliun * 1000 ^ 4 - milyar * 1000 ^ 3 - juta * 1000 ^ 2) / 1000)
satu = Int(x - triliun * 1000 ^ 4 - milyar * 1000 ^ 3 - juta * 1000 ^ 2 - ribu * 1000)
sen = Int((x - Int(x)) * 100)
'Baca bagian triliun dan ditambah akhiran triliun
If triliun > 0 Then
baca = ratus(triliun, 5) + "triliun "
End If
'Baca bagian milyar dan ditambah akhiran milyar
If milyar > 0 Then
baca = ratus(milyar, 4) + "milyar "
End If
'Baca bagian juta dan ditambah akhiran juta
If juta > 0 Then
baca = baca + ratus(juta, 3) + "juta "
End If
'Baca bagian ribu dan ditambah akhiran ribu
If ribu > 0 Then
baca = baca + ratus(ribu, 2) + "ribu "
End If
'Baca bagian rupiah dan ditambah akhiran rupiah
If satu > 0 Then
baca = baca + ratus(satu, 1) + "rupiah "
Else
baca = baca + "rupiah"
End If
'Baca bagian sen dan ditambah akhiran sen
If sen > 0 Then
baca = baca + ratus(sen, 0) + "sen"
End If
End If
Terbilang = UCase(Left(baca, 1)) & LCase(Mid(baca, 2))
End Function

Function ratus(x As Currency, Posisi As Integer) As String
Dim a100 As Integer, a10 As Integer, a1 As Integer
Dim baca As String
a100 = Int(x * 0.01)
a10 = Int((x - a100 * 100) * 0.1)
a1 = Int(x - a100 * 100 - a10 * 10)
'Baca Bagian Ratus
If a100 = 1 Then
baca = "Seratus "
Else
If a100 > 0 Then
baca = angka(a100, Posisi) + "ratus "
End If
End If
'Baca Bagian Puluh dan Satuan
If a10 = 1 Then
baca = baca + angka(a10 * 10 + a1, Posisi)
Else
If a10 > 0 Then
baca = baca + angka(a10, Posisi) + "puluh "
End If
If a1 > 0 Then
baca = baca + angka(a1, Posisi)
End If
End If
ratus = baca
End Function

Function angka(x As Integer, Posisi As Integer)
Select Case x
Case 0: angka = "Nol"
Case 1:
If Posisi <= 1 Or Posisi > 2 Then
angka = "Satu "
Else
angka = "Se"
End If
Case 2: angka = "Dua "
Case 3: angka = "Tiga "
Case 4: angka = "Empat "
Case 5: angka = "Lima "
Case 6: angka = "Enam "
Case 7: angka = "Tujuh "
Case 8: angka = "Delapan "
Case 9: angka = "Sembilan "
Case 10: angka = "Sepuluh "
Case 11: angka = "Sebelas "
Case 12: angka = "Duabelas "
Case 13: angka = "Tigabelas "
Case 14: angka = "Empatbelas "
Case 15: angka = "Limabelas "
Case 16: angka = "Enambelas "
Case 17: angka = "Tujuhbelas "
Case 18: angka = "Delapanbelas "
Case 19: angka = "Sembilanbelas "
End Select
End Function

semua udah ditest 100% working
selamat mencoba dan di modif sendiri :D:D:D
 
Back
Top