Skip to content

Instantly share code, notes, and snippets.

@eghojansu
Created April 27, 2021 09:52
Show Gist options
  • Save eghojansu/c77c5ace9333c062d636d0f5f7f57c2b to your computer and use it in GitHub Desktop.
Save eghojansu/c77c5ace9333c062d636d0f5f7f57c2b to your computer and use it in GitHub Desktop.
Crystal Report Custom [Basic Language] [No Recursive] Function, Terbilang Bahasa Indonesia
Function Bilangan (numb as Number) as String
Select Case numb
Case 0
Bilangan = "nol"
Case 1
Bilangan = "satu"
Case 2
Bilangan = "dua"
Case 3
Bilangan = "tiga"
Case 4
Bilangan = "empat"
Case 5
Bilangan = "lima"
Case 6
Bilangan = "enam"
Case 7
Bilangan = "tujuh"
Case 8
Bilangan = "delapan"
Case 9
Bilangan = "sembilan"
Case 10
Bilangan = "sepuluh"
Case 11
Bilangan = "sebelas"
Case Else
Bilangan = ToText(numb)
End Select
End Function
Function Terbilang(numb as Number) as String
Dim real, realLoop, realReal, realReduce, realMultiply, realNext, realNextCtr, unit, fraction, fractionLen, i as Number
Dim realTxt, fractionTxt, suffix as String
Dim units (), realNexts () as Number
Dim realNextSuffixes () as String
units = Array (12, 9, 6, 3, 2, 1)
fraction = numb - Floor(numb)
fractionTxt = ToText(fraction)
fractionLen = Len(fractionTxt)
real = numb - fraction
realTxt = ToText(real)
realLoop = real
Terbilang = ""
realNext = 0
realNextCtr = 0
While realLoop > 0
suffix = ""
If realLoop < 12 Then
Terbilang = Terbilang + " " + Bilangan(realLoop)
realLoop = 0
ElseIf realLoop < 20 Then
Terbilang = Terbilang + Bilangan(realLoop - 10) + " belas"
realLoop = 0
Else
For i = 1 To UBound(units)
unit = units(i)
realMultiply = 10^unit
realReal = Floor(realLoop / realMultiply)
If realReal > 0 Then
realReduce = realReal * realMultiply
Select Case unit
Case 12
suffix = " trilyun"
Case 9
suffix = " milyar"
Case 6
suffix = " juta"
Case 3
suffix = " ribu"
Case 2
suffix = " ratus"
Case Else
suffix = " puluh"
End Select
If realReal = 1 And (unit = 3 OR unit = 2) Then
Terbilang = Terbilang + " Se"
suffix = Trim(suffix)
realLoop = realLoop - realReduce
ElseIf realReal > 11 Then
realNextCtr = realNextCtr + 1
Redim Preserve realNexts(realNextCtr)
Redim Preserve realNextSuffixes(realNextCtr)
realNexts(realNextCtr) = realLoop - realReduce
realNextSuffixes(realNextCtr) = suffix
realLoop = realReal
suffix = ""
Exit For
Else
Terbilang = Terbilang + " " + Bilangan(realReal)
realLoop = realLoop - realReduce
End If
Exit For
End If
Next i
End If
Terbilang = Terbilang + suffix
If realLoop = 0 And realNext < UBound(realNexts) Then
realNext = realNext + 1
realLoop = realNexts(realNext)
Terbilang = Terbilang + realNextSuffixes(realNext)
End If
Wend
If fraction > 0 Then
Terbilang = Terbilang + " koma"
For i = 3 To fractionLen
Terbilang = Terbilang + " " + Bilangan(ToNumber(fractionTxt(i)))
Next i
End If
Terbilang = Trim(Terbilang)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment