Number to Text Routine?

Ben Weinberg ben at pca.com
Sat Jul 23 19:14:03 UTC 2022


After posting this code, I found a bug where it didn’t print the Dollars value correctly.  I rebuilt it and am submitting it in the interest of not having buggy code on the list.
Other versions of this function have also been submitted that are shorter and more concise than this one.

Ben Weinberg

No.	Instance Variable	Type	Subtype	Init.Val/Calc	Description
1	iAccountsCombined	Character	60
2	iAmountSpeak	Character	90
3	iAmountString	Character	10
4	iCents	32 bit integer
5	icoOnes	Character	10
6	icoOnesList	List
7	icoTens	Character	10
8	icoTensList	List
9	iDollars	Number	floating dp
10	iHundreds	Number	floating dp
11	iHundredsTotal	Number	floating dp
12	iSplitsList	List
13	iTens	Number	floating dp
14	iTensTotal	Number	floating dp
15	iTenThousands	Number	floating dp
16	iThousands	Number	floating dp
17	iThousandsTotal	Number	floating dp


# Convert numeric amount into words
# Make currency lists
Do icoOnesList.$define(icoOnes)
Do icoOnesList.$clear()
Do icoOnesList.$add('One')
Do icoOnesList.$add('Two')
Do icoOnesList.$add('Three')
Do icoOnesList.$add('Four')
Do icoOnesList.$add('Five')
Do icoOnesList.$add('Six')
Do icoOnesList.$add('Seven')
Do icoOnesList.$add('Eight')
Do icoOnesList.$add('Nine')
Do icoOnesList.$add('Ten')
Do icoOnesList.$add('Eleven')
Do icoOnesList.$add('Twelve')
Do icoOnesList.$add('Thirteen')
Do icoOnesList.$add('Fourteen')
Do icoOnesList.$add('Fifteen')
Do icoOnesList.$add('Sixteen')
Do icoOnesList.$add('Seventeen')
Do icoOnesList.$add('Eighteen')
Do icoOnesList.$add('Nineteen')

Do icoTensList.$define(icoTens)
Do icoTensList.$clear()
Do icoTensList.$add('Ten')
Do icoTensList.$add('Twenty')
Do icoTensList.$add('Thirty')
Do icoTensList.$add('Forty')
Do icoTensList.$add('Fifty')
Do icoTensList.$add('Sixty')
Do icoTensList.$add('Seventy')
Do icoTensList.$add('Eighty')
Do icoTensList.$add('Ninety')

Clear range of fields iAmountSpeak to iThousandsTotal
Calculate iAmountString as FTRANSACTIONS.trAmount

Calculate iCents as (FTRANSACTIONS.trAmount-int(FTRANSACTIONS.trAmount))*100

If len(iAmountString)>3
Calculate iDollars as mid(iAmountString,len(iAmountString)-3,1)
End If
If len(iAmountString)>4
Calculate iTens as mid(iAmountString,len(iAmountString)-4,1)
End If
If len(iAmountString)>5
Calculate iHundreds as mid(iAmountString,len(iAmountString)-5,1)
End If
If len(iAmountString)>6
Calculate iThousands as mid(iAmountString,len(iAmountString)-6,1)
End If
If len(iAmountString)>7
Calculate iTenThousands as mid(iAmountString,len(iAmountString)-7,1)
End If

# Calculate totals to determine which list to use (Ones or Tens)
Calculate iTensTotal as (iTens*10+iDollars)
Calculate iHundredsTotal as (iHundreds*100)+(iTens*10)+iDollars
Calculate iThousandsTotal as (iTenThousands*10)+iThousands

# If thousands is between 1 and 19, use the Ones list
If iThousandsTotal>0&iThousandsTotal<20
Do icoOnesList.$line.$assign(iThousandsTotal)
Do icoOnesList.$loadcols(icoOnes)
Calculate iAmountSpeak as con(icoOnes,' Thousand ')

Else
# Thousands is 20 or more, use the Tens list
Do icoTensList.$line.$assign(iTenThousands)
Do icoTensList.$loadcols(icoTens)
Calculate iAmountSpeak as con(icoTens,' ')

# One-thousands use the Ones list
If iThousands>0
Do icoOnesList.$line.$assign(iThousands)
Do icoOnesList.$loadcols(icoOnes)
Calculate iAmountSpeak as con(iAmountSpeak,icoOnes,' Thousand ')
End If
End If

# Hundreds use the Ones list
If iHundreds>0
Do icoOnesList.$line.$assign(iHundreds)
Do icoOnesList.$loadcols(icoOnes)
Calculate iAmountSpeak as con(iAmountSpeak,icoOnes,' Hundred ')
End If

# If tens between 1 and 19, use the Ones list
If iTensTotal>0&iTensTotal<20
Do icoOnesList.$line.$assign(iTensTotal)
Do icoOnesList.$loadcols(icoOnes)
Calculate iAmountSpeak as con(iAmountSpeak,icoOnes,' Dollars')

Else
# Tens 20 or more, use the Tens list
Do icoTensList.$line.$assign(iTens)
Do icoTensList.$loadcols(icoTens)
Calculate iAmountSpeak as con(iAmountSpeak,icoTens,' ',)

# Ones
If iDollars>0
Do icoOnesList.$line.$assign(iDollars)
Do icoOnesList.$loadcols(icoOnes)
Calculate iAmountSpeak as con(iAmountSpeak,icoOnes,' Dollars')
Else
Calculate iAmountSpeak as con(iAmountSpeak,' Dollars')
End If
End If

# Cents
If iCents>0
Calculate iAmountSpeak as con(iAmountSpeak,' and ',iCents,'/100 ')
Else
Calculate iAmountSpeak as con(iAmountSpeak,' and ','no/100 ')
End If

Do default




More information about the omnisdev-en mailing list