Alaska Software Inc. - Currency conversion to words
Username: Password:
AuthorTopic: Currency conversion to words
Jack Currency conversion to words
on Thu, 10 Mar 2005 12:02:34 +0100
We need to find a function that converts currency numbers into words. 
$122.00 into One hundred twenty two dollars.

In Clipper we had a library but it doesn't work in xBase. 

Any help/suggestions would be appreciated. I really don't want to have to 
write one myself.

TIA.

Jack

Jack Miller
Jack@my-esa.com
Donald R. KeatingRe: Currency conversion to words
on Thu, 10 Mar 2005 08:00:30 -0500
On Thu, 10 Mar 2005 12:02:34 +0100, Jack wrote:

> We need to find a function that converts currency numbers into words. 
> $122.00 into One hundred twenty two dollars.
> 
> In Clipper we had a library but it doesn't work in xBase. 
> 
> Any help/suggestions would be appreciated. I really don't want to have to 
> write one myself.
> 
> TIA.
> 
> Jack
> 
> Jack Miller
> Jack@my-esa.com

Jack,

Attached is one I found in one of my old Clipper apps that is still in use.
So, I know it works.  

You'll note it uses PageScript so, will require some changes for your use
in Xbase++ app.

FYI, I got the original idea and code from page 612 of "Programming in
Clipper" second edition by Stephen J.Straley.

HTH,

   >don<


ChkAmnt.FNC
Jack Re: Currency conversion to words
on Thu, 10 Mar 2005 14:22:15 +0100
"Donald R. Keating" <DonK@dbscompany.com> wrote in 
news:1h411tuym4svv.1ss24z29exi19$.dlg@40tude.net:

> Attachment decoded: ChkAmnt.FNC

Thanks, Don.

I'll take a look and let you know.

FYI, I used to have that book, but haven't seen for several years. Wouldn't 
know where to start looking 'cause we've moved and God only knows where my 
old Clipper stuff is. LOL

Thanks, again.

Jack
James Loughner Re: Currency conversion to words
on Thu, 10 Mar 2005 10:10:08 -0500
Jack wrote:

> We need to find a function that converts currency numbers into words. 
> $122.00 into One hundred twenty two dollars.
> 
> In Clipper we had a library but it doesn't work in xBase. 
> 
> Any help/suggestions would be appreciated. I really don't want to have to 
> write one myself.
> 
> TIA.
> 
> Jack
> 
> Jack Miller
> Jack@my-esa.com
> 

Watch the line wrapping

FUNCTION EnglishNum(Number)
LOCAL Count,Start,String,Result,Chunk
PRIVATE 
U,U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U30,U40,U50,U60,U70,U80,U90
PRIVATE Hun,Ten,One

    U   := " "
    U1  := "ONE"
    U2  := "TWO"
    U3  := "THREE"
    U4  := "FOUR"
    U5  := "FIVE"
    U6  := "SIX"
    U7  := "SEVEN"
    U8  := "EIGHT"
    U9  := "NINE"
    U10 := "TEN"
    U11 := "ELEVEN"
    U12 := "TWELVE"
    U13 := "THIRTEEN"
    U14 := "FOURTEEN"
    U15 := "FIFTEEN"
    U16 := "SIXTEEN"
    U17 := "SEVENTEEN"
    U18 := "EIGHTEEN"
    U19 := "NINETEEN"
    U20 := "TWENTY"
    U30 := "THIRTY"
    U40 := "FORTY"
    U50 := "FIFTY"
    U60 := "SIXTY"
    U70 := "SEVENTY"
    U80 := "EIGHTY"
    U90 := "NINTY"

    ********** SET UP VARIABLES
    Counter := 1
    Start   := 1
    String  := STR(Number,9,2)
    Result  := " "
    ******************* Loop through thousands and hundreds.
    DO WHILE Counter < 3
       *****************Split out hundreds, tens, and ones.
       Chunk := SUBSTR(String,Start,3)
       Hun   := SUBSTR(Chunk,1,1)
       Ten   := SUBSTR(Chunk,2,2)
       One   := SUBSTR(Chunk,3,1)
       ***************** Hundreds
       IF VAL(Chunk)> 99
           Result := Result + U&Hun + " HUNDRED "
       ENDIF
       ***************** Handle second 2 digits.
       T := VAL(Ten)
       IF T > 0
          DO CASE
            ********************CASE 1 EVEN TENS AND TEENS
            CASE (INT(T/10.0)=T/10.0) .OR. (T>9 .AND. T<20)
               Result := Result + U&Ten

            ********************CASE 2  > 10
            CASE T > 9 .AND. (INT(T/10.0)#T/10.0)
               Ten := SUBSTR(Ten,1,1) + "0"
               Result := Result + U&Ten + " " + U&One

            ********************CASE 3 < 10
            CASE T < 10
               Result := Result + U&One
          ENDCASE
       ENDIF
       ********** Add "Thousand" if necessary
       IF Number > 999.99 .AND. Counter = 1
          Result := Result+" THOUSAND "
       ENDIF
       Start := 4
       Counter := Counter + 1
    ENDDO

    *********** Tack on cents
    IF INT(Number) > 0
       Result := Result + " AND "
    ENDIF

    Result := Result + SUBSTR(String,8,2)+"/100"

RETURN(Result)
Marco AguiarRe: Currency conversion to words
on Thu, 10 Mar 2005 17:44:22 +0000
Hi,

I use the following function ( but it is in Portuguese ) :

**************************************

  cText := MyNumTxt(  122.50 )
*
**************************************

FUNC MyNumTxt( PM1, PM2, PM3, PM4, PM5, PM6 )
   LOCAL VML := {}, VT1 := {}
   LOCAL TX0 := "", TY0 := ""
   LOCAL Lx0 := 0 , Ly0 := 0 , VL0 := 0
   Default PM6 to "BILIOES"
   Default PM5 to "MILHOES"
   Default PM4 to "MIL"
   Default PM3 to "CENTIMOS"
   Default PM2 to "EUROS"
   Default PM1 to 0

   PM6 := IIF( !EMPTY(PM6), ALLTRIM(PM6)+" ", "" )
   PM5 := IIF( !EMPTY(PM5), ALLTRIM(PM5)+" ", "" )
   PM4 := IIF( !EMPTY(PM4), ALLTRIM(PM4)+" ", "" )
   PM3 := IIF( !EMPTY(PM3), ALLTRIM(PM3)+" ", "" )
   PM2 := IIF( !EMPTY(PM2), ALLTRIM(PM2)+" ", "" )
   PM1 := STR( PM1, 15, 02 )

   VML := { VAL( SUBSTR( PM1, 01, 3 ) ),;
            VAL( SUBSTR( PM1, 04, 3 ) ),;
            VAL( SUBSTR( PM1, 07, 3 ) ),;
            VAL( SUBSTR( PM1, 10, 3 ) ),;
            VAL( SUBSTR( PM1, 14, 2 ) ) }

   VT1 := { { 900, "NOVECENTOS "   },;
            { 800, "OITOCENTOS "   },;
            { 700, "SETECENTOS "   },;
            { 600, "SEISCENTOS "   },;
            { 500, "QUINHENTOS "   },;
            { 400, "QUATROCENTOS " },;
            { 300, "TREZENTOS "    },;
            { 200, "DUZENTOS "     },;
            { 101, "CENTO "        },;
            { 100, "CEM "          },;
            {  90, "NOVENTA "      },;
            {  80, "OITENTA "      },;
            {  70, "SETENTA "      },;
            {  60, "SESSENTA "     },;
            {  50, "CINQUENTA "    },;
            {  40, "QUARENTA "     },;
            {  30, "TRINTA "       },;
            {  20, "VINTE "        },;
            {  19, "DEZANOVE "     },;
            {  18, "DEZOITO "      },;
            {  17, "DEZASSETE "    },;
            {  16, "DEZASSEIS "    },;
            {  15, "QUINZE "       },;
            {  14, "CATORZE "      },;
            {  13, "TREZE "        },;
            {  12, "DOZE "         },;
            {  11, "ONZE "         },;
            {  10, "DEZ "          },;
            {   9, "NOVE "         },;
            {   8, "OITO "         },;
            {   7, "SETE "         },;
            {   6, "SEIS "         },;
            {   5, "CINCO "        },;
            {   4, "QUATRO "       },;
            {   3, "TRES "         },;
            {   2, "DOIS "         },;
            {   1, "UM "           } }

   For Lx0 = 1 TO 5
       TX0 := ""
       VL0 := VML[Lx0]
       For Ly0 = 1 to 10
           if VL0 >= VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VL0 >= 20 .AND. !EMPTY(TX0), "E ", "" )
       For Ly0 = 11 TO 18
           if VL0 >= VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VL0 >=  9 .AND. !EMPTY(TX0), "E ", "" )
       For Ly0 = 19 TO 37
           if VL0  = VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VML[1] > 0 .AND. Lx0 = 1, PM6, "" )
       TX0 += IIF( VML[2] > 0 .AND. Lx0 = 2, PM5, "" )
       TX0 += IIF( VML[3] > 0 .AND. Lx0 = 3, PM4, "" )
       TX0 += IIF( VML[4] > 0 .AND. Lx0 = 4, PM2, "" )
       TX0 += IIF( VML[5] > 0 .AND. Lx0 = 5, PM3, "" )
       TY0 += TX0
   Next

Return TY0

*********************************************


"Jack" <Jack@my-esa.com> escreveu na mensagem 
news:Xns96153D8BBAF86Jackmyesacom@217.160.95.134...
> We need to find a function that converts currency numbers into words.
> $122.00 into One hundred twenty two dollars.
>
> In Clipper we had a library but it doesn't work in xBase.
>
> Any help/suggestions would be appreciated. I really don't want to have to
> write one myself.
>
> TIA.
>
> Jack
>
> Jack Miller
> Jack@my-esa.com
>
Marco AguiarRe: Currency conversion to words
on Thu, 10 Mar 2005 18:11:31 +0000
Hi,

I use the following function ( but it is in Portuguese ) :

**************************************

  cText := MyNumTxt(  122.50 )
*
**************************************

FUNC MyNumTxt( PM1, PM2, PM3, PM4, PM5, PM6 )
   LOCAL VML := {}, VT1 := {}
   LOCAL TX0 := "", TY0 := ""
   LOCAL Lx0 := 0 , Ly0 := 0 , VL0 := 0
   Default PM6 to "BILIOES"
   Default PM5 to "MILHOES"
   Default PM4 to "MIL"
   Default PM3 to "CENTIMOS"
   Default PM2 to "EUROS"
   Default PM1 to 0

   PM6 := IIF( !EMPTY(PM6), ALLTRIM(PM6)+" ", "" )
   PM5 := IIF( !EMPTY(PM5), ALLTRIM(PM5)+" ", "" )
   PM4 := IIF( !EMPTY(PM4), ALLTRIM(PM4)+" ", "" )
   PM3 := IIF( !EMPTY(PM3), ALLTRIM(PM3)+" ", "" )
   PM2 := IIF( !EMPTY(PM2), ALLTRIM(PM2)+" ", "" )
   PM1 := STR( PM1, 15, 02 )

   VML := { VAL( SUBSTR( PM1, 01, 3 ) ),;
            VAL( SUBSTR( PM1, 04, 3 ) ),;
            VAL( SUBSTR( PM1, 07, 3 ) ),;
            VAL( SUBSTR( PM1, 10, 3 ) ),;
            VAL( SUBSTR( PM1, 14, 2 ) ) }

   VT1 := { { 900, "NOVECENTOS "   },;
            { 800, "OITOCENTOS "   },;
            { 700, "SETECENTOS "   },;
            { 600, "SEISCENTOS "   },;
            { 500, "QUINHENTOS "   },;
            { 400, "QUATROCENTOS " },;
            { 300, "TREZENTOS "    },;
            { 200, "DUZENTOS "     },;
            { 101, "CENTO "        },;
            { 100, "CEM "          },;
            {  90, "NOVENTA "      },;
            {  80, "OITENTA "      },;
            {  70, "SETENTA "      },;
            {  60, "SESSENTA "     },;
            {  50, "CINQUENTA "    },;
            {  40, "QUARENTA "     },;
            {  30, "TRINTA "       },;
            {  20, "VINTE "        },;
            {  19, "DEZANOVE "     },;
            {  18, "DEZOITO "      },;
            {  17, "DEZASSETE "    },;
            {  16, "DEZASSEIS "    },;
            {  15, "QUINZE "       },;
            {  14, "CATORZE "      },;
            {  13, "TREZE "        },;
            {  12, "DOZE "         },;
            {  11, "ONZE "         },;
            {  10, "DEZ "          },;
            {   9, "NOVE "         },;
            {   8, "OITO "         },;
            {   7, "SETE "         },;
            {   6, "SEIS "         },;
            {   5, "CINCO "        },;
            {   4, "QUATRO "       },;
            {   3, "TRES "         },;
            {   2, "DOIS "         },;
            {   1, "UM "           } }

   For Lx0 = 1 TO 5
       TX0 := ""
       VL0 := VML[Lx0]
       For Ly0 = 1 to 10
           if VL0 >= VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VL0 >= 20 .AND. !EMPTY(TX0), "E ", "" )
       For Ly0 = 11 TO 18
           if VL0 >= VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VL0 >=  9 .AND. !EMPTY(TX0), "E ", "" )
       For Ly0 = 19 TO 37
           if VL0  = VT1[Ly0,1]
              TX0 += VT1[Ly0,2]
              VL0 -= VT1[Ly0,1]
           endif
       Next
       TX0 += IIF( VML[1] > 0 .AND. Lx0 = 1, PM6, "" )
       TX0 += IIF( VML[2] > 0 .AND. Lx0 = 2, PM5, "" )
       TX0 += IIF( VML[3] > 0 .AND. Lx0 = 3, PM4, "" )
       TX0 += IIF( VML[4] > 0 .AND. Lx0 = 4, PM2, "" )
       TX0 += IIF( VML[5] > 0 .AND. Lx0 = 5, PM3, "" )
       TY0 += TX0
   Next

Return TY0

*********************************************


"Jack" <Jack@my-esa.com> escreveu na mensagem
news:Xns96153D8BBAF86Jackmyesacom@217.160.95.134...
> We need to find a function that converts currency numbers into words.
> $122.00 into One hundred twenty two dollars.
>
> In Clipper we had a library but it doesn't work in xBase.
>
> Any help/suggestions would be appreciated. I really don't want to have to
> write one myself.
>
> TIA.
>
> Jack
>
> Jack Miller
> Jack@my-esa.com
>
Alain RousseauRe: Currency conversion to words
on Sat, 12 Mar 2005 12:46:15 +0100
Hello Jack

I have a program to convert number to words.
It's a program in FRENCH. The program is more longer
than the program of James Loughner.

With the own rules of french
(singular and plurial  -> sorry for the bad translation)
and
1250 ->        mille         deux cents     cinquante          in french
1250 -> one thousands two   hundred fifty
Look the "one" don't exist in french. It's french exception
2399 -> deux milles        trois  cents      nonante-neuf
2399 -> two   thousands three hundred ninty nine

This program insert "euros" and "centimes"
and it convert the cent in words.

Limits 99999.99


I hope that the program can help you with minor modification.( and
translation)
and replace "euros" by "dollars"

Bye

Alain Rousseau


"Jack" <Jack@my-esa.com> a crit dans le message de
news:Xns96153D8BBAF86Jackmyesacom@217.160.95.134...
> We need to find a function that converts currency numbers into words.
> $122.00 into One hundred twenty two dollars.
>
> In Clipper we had a library but it doesn't work in xBase.
>
> Any help/suggestions would be appreciated. I really don't want to have to
> write one myself.
>
> TIA.
>
> Jack
>
> Jack Miller
> Jack@my-esa.com
>



Nbfr.prg