I am using the program offered for printing checks. The problem I am having is that the text, of the dollar amounts, does not match the monetary dollar amount (number value). As an example I would like $1405.89 converted to one thousand four hundred five and 89/100************ The dollar value is always written correctly, it's the cents value that is generally wrong.
I basically have two elenents Net, which has the numerical monetary value and Amount which has the converted monetary value in text form.
I am enclosing the programing for the Amount element for your review.
Appreciate any help, Peter
/* Money value to text converter by Tom Marcellus 9/2003 For amounts less than $1 million Converts an amount like $3025.55 to Three Thousand Twenty Five and 55/100 Requires Money field named "Net" and Text field named "Words" */
var vNet as String var vWords as String var Dollars as String var Cents as String var Chunk as String var digits as Int var leftdigit as Int var rightdigit as Int var BigOnes as array[9] of String var SmallOnes as array[19] of String
Subroutine ParseChunk() //########
digits = @Left(Chunk, 1)
If digits > 0 Then { vWords = vWords + " " + SmallOnes[digits] + " Hundred" }
digits = @Mid(Chunk, 2, 2)
If digits > 19 Then { leftdigit = @Mid(Chunk, 2, 1) rightdigit = @Mid(Chunk, 3, 1) vWords = vWords + " " + BigOnes[leftdigit] }
If rightdigit > 0 Then { vWords = vWords + " " + SmallOnes[rightdigit] }
Else
If (digits <= 19) and (digits > 0) Then { vWords = vWords + " " + SmallOnes[digits] }
End Subroutine //##################
vNet = Net
If vNet = "0" Then STOP
If @Int(vNet) > 999999 Then { @Msgbox("","Dollar amount too large.","") STOP }
If @Instr(vNet, ".") = 0 Then { vNet = vNet + ".00" }
// Fill the two arrays.
BigOnes[1] = "Ten" BigOnes[2] = "Twenty" BigOnes[3] = "Thirty" BigOnes[4] = "Forty" BigOnes[5] = "Fifty" BigOnes[6] = "Sixty" BigOnes[7] = "Seventy" BigOnes[8] = "Eighty" BigOnes[9] = "Ninety"
SmallOnes[1] = "One" SmallOnes[2] = "Two" SmallOnes[3] = "Three" SmallOnes[4] = "Four" SmallOnes[5] = "Five" SmallOnes[6] = "Six" SmallOnes[7] = "Seven" SmallOnes[8] = "Eight" SmallOnes[9] = "Nine" SmallOnes[10] = "Ten" SmallOnes[11] = "Eleven" SmallOnes[12] = "Twelve" SmallOnes[13] = "Thirteen" SmallOnes[14] = "Fourteen" SmallOnes[15] = "Fifteen" SmallOnes[16] = "Sixteen" SmallOnes[17] = "Seventeen" SmallOnes[18] = "Eighteen" SmallOnes[19] = "Nineteen"
// Separate the dollars from the cents // Format incoming number to ensure 6 digits // to the left of the decimal & 2 to the right
Dollars = @Left(vNet, @Instr(vNet, ".") -1 ) Dollars = @Right("000000" + Dollars, 6) Cents = @Right(vNet, 2) Cents = @Right("00" + Cents, 2)
// Separate the dollars into chunks
If @Int(Dollars) = 0 Then vWords = "Zero"
Else {
// First do the thousands
Chunk = @Left(Dollars, 3)
If @Int(Chunk) > 0 Then { ParseChunk() vWords = vWords + " Thousand" }
// Do the rest of the dollars
Chunk = @Right(Dollars, 3)
If @Int(Chunk) > 0 Then ParseChunk() }
// Concatenate the cents and display
//If Cents = 0 Then //Cents = "00"
vWords = vWords + " and " + Cents + "/100"
// Add asterisks to pad out the text string
If @Len(vWords) < 60 Then vWords = vWords + @Text(60 - @Len(vWords), "*")
Amount = vWords @Msg(vWords)
// Use words = toUpper(vWords) for all uppercase
|