# Number to Text Routine?

Ben Weinberg ben at pca.com
Fri Jul 22 20:25:52 UTC 2022

```Das:

Funny you should ask…
I just wrote this a few weeks ago after looking around and not finding any examples.  It’s most likely done the hard way but gets the job done.

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	icoTens	Character	10
7	iDollars	Number	floating dp
8	iHundreds	Number	floating dp
9	iHundredsTotal	Number	floating dp
10	iSplitsList	List
11	iTens	Number	floating dp
12	iTensTotal	Number	floating dp
13	iTenThousands	Number	floating dp
14	iThousands	Number	floating dp
15	iThousandsTotal	Number	floating dp

# Convert numeric amount into words

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 FCOMPANY.coOnesList.\$line.\$assign(iThousandsTotal)
Calculate iAmountSpeak as con(icoOnes,' Thousand ')

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

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

# Hundreds use the Ones lisst
If iHundreds>0
Do FCOMPANY.coOnesList.\$line.\$assign(iHundreds)
Calculate iAmountSpeak as con(iAmountSpeak,' ',icoOnes,' Hundred ')
End If

# If tens between 1 and 19, use the Ones list
If iTensTotal<20
Do FCOMPANY.coOnesList.\$line.\$assign(iTensTotal)
Calculate iAmountSpeak as con(iAmountSpeak,' ',icoOnes,' Dollars')

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

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

# Cents
Calculate iAmountSpeak as con(iAmountSpeak,' and ',iCents,'/100 ')

Do default

--------------
Requires two lists:
icoOnes:
One
Two
...
Nineteen

icoTens:
Ten
Twenty
...
Ninety

> On Jul 22, 2022, at 12:50 PM, Das Goravani <goravanis at gmail.com> wrote:
>
>
> Hello All,
>
> One thing I’m working on is the printing of checks.
>
> It’s one thing to have the amount as a number, that’s normal, but to print the check I need the amount in text like:
>
> One Thousand Seven Hundred Thirty Four and 68 cents
>
> Does anyone have a routine that does this conversion ?
>
> I think I could write one, but it would be a bit long, someone might do it smarter than I could do it.
>
> Thanks
>
> Das Goravani
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com

```