Dim number As Decimal = 4989654321.85
Dim currencyCode As String = "USD"
Dim fractionName As String = "cents"
Dim result as String = ConvertDecimalToWords(number, currencyCode, fractionName)
Console.WriteLine(result)
Public Function ConvertDecimalToWords(ByVal number As Decimal, ByVal currencyCode As String, ByVal fractionName As String) As String
Dim ones() As String = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine "}
Dim tens() As String = {"", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "}
Dim teens() As String = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen "}
Dim scale() As String = {"", "Thousand ", "Million ", "Billion ", "Trillion ", "Quadrillion ", "Quintillion "}
Dim isNegative As Boolean = (number < 0)
number = Math.Abs(number)
Dim intNumber As Long = Math.Truncate(number)
Dim fraction As Integer = CInt(Math.Round((number - intNumber) * 100))
Dim groupCount As Integer = 0
groups(groupCount) = intNumber Mod 1000
For i As Integer = groupCount - 1 To 0 Step -1
Dim groupNumber As Integer = groups(i)
Dim hundreds As Integer = groupNumber \ 100
Dim tensUnits As Integer = groupNumber Mod 100
words &= ones(hundreds) & "Hundred "
ElseIf tensUnits < 20 Then
words &= teens(tensUnits - 10)
words &= tens(tensUnits \ 10)
If (tensUnits Mod 10) > 0 Then
words &= ones(tensUnits Mod 10)
words &= currencyCode & " "
Dim tensUnits As Integer = fraction Mod 100
ElseIf tensUnits < 20 Then
words &= teens(tensUnits - 10)
words &= tens(tensUnits \ 10)
If (tensUnits Mod 10) > 0 Then
words &= ones(tensUnits Mod 10)
words &= fractionName & " "