Here is a solution I wrote in VB which will convert any money value below 99,999,999.99 into text which will be gramatically correct. You could butcher this to get what you need
' PayNum is a monetry value, in this case £GBPounds, with or without decimal places for pence
' The returned string is gramatically correct, as if you wrote a cheque (check)
Option Explicit
Dim strUnder21(1 To 20) As String
Dim strTens(1 To 9) As String
Public Function NumToConvert(PayNum As String) As String
' Initialise the arrays
strUnder21(1) = "One "
strUnder21(2) = "Two "
strUnder21(3) = "Three "
strUnder21(4) = "Four "
strUnder21(5) = "Five "
strUnder21(6) = "Six "
strUnder21(7) = "Seven "
strUnder21(8) = "Eight "
strUnder21(9) = "Nine "
strUnder21(10) = "Ten "
strUnder21(11) = "Eleven "
strUnder21(12) = "Twelve "
strUnder21(13) = "Thirteen "
strUnder21(14) = "Fourteen "
strUnder21(15) = "Fifteen "
strUnder21(16) = "Sixteen "
strUnder21(17) = "Seventeen"
strUnder21(18) = "Eighteen "
strUnder21(19) = "Nineteen "
strUnder21(20) = "Twenty "
strTens(1) = "Ten "
strTens(2) = "Twenty "
strTens(3) = "Thirty "
strTens(4) = "Fourty "
strTens(5) = "Fifty "
strTens(6) = "Sixty "
strTens(7) = "Seventy "
strTens(8) = "Eighty "
strTens(9) = "Ninety "
NumToConvert = PoundsPence(PayNum)
End Function
Public Function PoundsPence(PayNum As String) As String
Dim Po As String, Pe As String, pence As Integer
Dim start As Integer, Nt As String
On Error GoTo Err_PoundsPence
start = InStr(PayNum, ".")
If start = 0 Then
Po = getPounds(PayNum, Nt)
Else
Po = Left(PayNum, start - 1)
pence = Val(Right(PayNum, Len(PayNum) - (Len(Po) + 1)))
PayNum = Po
Po = getPounds(PayNum, Nt)
If getDigitsToText(pence, Nt) Then
Pe = Nt & " pence"
Pe = Replace(Pe, " ", " ")
End If
End If
PoundsPence = Po & Pe
PoundsPence = UCase(Left(PoundsPence, 1)) & LCase(Right(PoundsPence, Len(PoundsPence) - 1))
Exit_PoundsPence:
Exit Function
Err_PoundsPence:
MsgBox Error$
Resume Exit_PoundsPence
End Function
Private Function getPounds(PayNum As String, Nt As String) As String
Dim Tm As Integer, Tms As String
Dim Ht As Integer, Hts As String
Dim tt As Integer, tts As String
Dim H As Integer, Hs As String
Dim t As Integer, ts As String
On Error GoTo Err_NumToText
Nt = Right("00000000" & PayNum, 8)
Tm = Val(Mid(Nt, Len(Nt) - 8 + 1, 2))
Ht = Val(Mid(Nt, Len(Nt) - 6 + 1, 1))
tt = Mid(Nt, Len(Nt) - 5 + 1, 2)
H = Val(Mid(Nt, Len(Nt) - 3 + 1, 1))
t = Val(Mid(Nt, Len(Nt) - 2 + 1, 2))
' Millions
If getDigitsToText(Tm, Tms) Then
Tms = Tms & "million "
End If
' Hundred Thousands
If getDigitsToText(Ht, Hts) Then
Hts = Hts & "hundred "
End If
' Ten thousands/ thousands
If getDigitsToText(tt, tts) Then
If Ht > 0 Then tts = "and " & tts
End If
If (Ht > 0) Or (tt > 0) Then
tts = tts & "thousand "
End If
' Hundreds
If getDigitsToText(H, Hs) Then
Hs = Hs & "hundred "
End If
' Tens and units
If getDigitsToText(t, ts) Then
If (Tm > 0) Or (Ht > 0) Or (tt > 0) Or (H > 0) Then ts = "and " & ts
End If
getPounds = Tms & Hts & tts & Hs & ts
getPounds = Replace(getPounds, " -", "-")
getPounds = Replace(getPounds, " ", " ")
If Len(getPounds & "") > 0 Then
getPounds = getPounds & "pounds "
End If
Exit_NumToText:
Exit Function
Err_NumToText:
MsgBox Error$
Resume Exit_NumToText
End Function
Private Function getDigitsToText(iNum As Integer, txtAmount As String) As Boolean
Dim iUnit As Integer
iUnit = iNum Mod 10
Select Case iNum
Case 0
txtAmount = ""
Case Is < 21
txtAmount = strUnder21(iNum)
Case Else
txtAmount = strTens((iNum - (iNum Mod 10)) / 10)
If iUnit > 0 Then
txtAmount = txtAmount & "-" & strUnder21(iUnit)
End If
End Select
getDigitsToText = (iNum > 0)
End Function