SHARED suffixes ASString() = _
{"Thousand ", "Million ", "Billion ", "Trillion ", _"Quadrillion ", "Quintillion ", "Sextillion "}SHARED units ASString() = _
{"","One ", "Two ", "Three ", "Four ", "Five ", _"Six ", "Seven ", "Eight ", "Nine "}SHARED tens ASString() = _
{"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", _"Seventy ", "Eighty ", "Ninety "}SHARED digits ASString() = _
{"Ten ","Eleven ", "Twelve ", "Thirteen ", "Fourteen ", _"Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen"}SHARED expr ASNEW _
System.Text.RegularExpressions.Regex("^-?\d+(\.\d{2})?$", _
System.Text.RegularExpressions.RegexOptions.None)PublicFunction ExpandPrice(Price ASDouble, Optional pSeparator ASString = ".") ASStringDim pPrice AsString
pPrice = FORMAT(Price,"##############.00")Dim temp ASNew System.Text.StringBuilder()IfNot expr.IsMatch(pPrice) Then' temp.Append(pPrice) or whatever you want to do here ElseDim parts ASString() = pPrice.Split(pSeparator)Dim dollars ASString = parts(0)Dim cents ASString = parts(1)IfCDbl(dollars) > 1 Then
temp.Append(ExpandIntegerNumber(dollars) & "Dollars ")IfCInt(cents) > 0 Then
temp.Append("And ")EndIfElseIfCDbl(dollars) = 0 Then
temp.Append(ExpandIntegerNumber(dollars) & "Zero Dollars ")IfCInt(cents) >= 0 Then
temp.Append("And ")EndIfElseIfCDbl(dollars) = 1 Then
temp.Append(ExpandIntegerNumber(dollars) & "Dollar " )EndIfIfCDbl(cents) > 1 Then
temp.Append(ExpandIntegerNumber(cents) & "Cents")ElseIfCDbl(cents) = 0 Then
temp.Append(ExpandIntegerNumber(cents) & "Zero Cents ")ElseIfCDbl(cents) = 1 Then
temp.Append(ExpandIntegerNumber(cents) & "Cent " )EndIfEndIfRETURN temp.ToString()EndFunctionFunction ExpandIntegerNumber(pNumberStr ASString) ASStringDim temp2 ASNew System.Text.StringBuilder()Dim number ASString = _
StrDup(3 - Len(pNumberStr) Mod 3, "0") & pNumberStrDim i ASInteger, j ASInteger = -1Dim numPart ASStringFor i = Len(number) - 2 To 1 Step -3
numPart = Mid(number, i, 3)
IfClng(numPart > 0) ThenIf j > -1 Then
temp2.Insert(0,suffixes(j),1)
EndIfEndIf
temp2.Insert(0,GetNumberUnder1000Str(numPart),1)
j += 1
NextRETURN temp2.ToString()EndFunctionFunction GetNumberUnder1000Str(pNumber ASString) ASStringDim temp1 ASNew System.Text.StringBuilder()If Len(pNumber) = 3 ThenIfCLng(Left(pNumber, 1)) > 0 Then
temp1.Append(GetNumberUnder100Str(Left(pNumber, 1)) & "Hundred ")EndIfEndIf
temp1.Append(GetNumberUnder100Str(Right("0"& pNumber, 2)))RETURN temp1.ToString()EndFunctionFunction GetNumberUnder100Str(pNumber ASString) ASStringIf pNumber > 19 ThenRETURN tens(Left(pNumber, 1) - 2) & units(Right(pNumber, 1))ElseIF pNumber >= 10 and pNumber <= 19 ThenRETURN digits(Right(pNumber, 1))ElseRETURN units(Right(pNumber, 1))EndIfEndFunction