Page 1 of 1

numeros a letras en ingles..

Posted: Thu Jan 10, 2013 2:39 am
by Arvisnet
Saludos..
alguien tendra una rutina para numeros a letras en ingles?...
Gracias.
Arnulfo V

Re: numeros a letras en ingles..

Posted: Thu Jan 10, 2013 4:54 am
by Bayron
Hace como 500 años, escribí algo para ingles y español, solo por la gana de hacerlo, mira si te sirve.

Puedes bajarlo de:
http://lawebdelprogramador.com/codigo/C ... adena.html

Mas bien lo pongo por aquí un poquito modificada, por si a alguien le sirve...

La cantidad que retorne en letras puede que sea muy larga, así que tendrás que partirla en partes si lo necesitas...

Code: Select all

/*          Author:    Bayron Landaverry
                       BL Computacion
                       6 Av. 3-26, zona 4
                       Chiquimula, Guatemala


            Version:   Clipper 5.3 (But it may run on other
                                    versions with only a few
                                    changes, I think it may, anyway)


            Comments:   Does not need external library's

                        Does not have color nor graphics, for
                        compatibility with your applications.

                        There is no guarantee on the application.

                        It can be used and distributed freely.

                        Please feel free to modify.
*/


///Procedure ConvNtoL
//   clear 
    
//   CDate     = DATE()
//   nAmount  = 0
//   nAmountL = Space(0)
    
//   @ 11, 36 Say CDate
//   @ 13, 35 Get nAmount Picture "9999999.99" Valid nAmount > 0
    
//   Read
    
//   nAmountL = NumToLet(nAmount)

//   @ 15, 0 Say nAmountL
    
//Return    
 


FUNCTION NumToLet(nAmount)
   //PARAMETERS nAmount
    
   LOCAL NToL[29, 1]
    
   NToL[ 1, 1] := "One " 
   NToL[ 2, 1] := "Two " 
   NToL[ 3, 1] := "Three "
   NToL[ 4, 1] := "Four " 
   NToL[ 5, 1] := "Five " 
   NToL[ 6, 1] := "Six " 
   NToL[ 7, 1] := "Seven " 
   NToL[ 8, 1] := "Eight " 
   NToL[ 9, 1] := "Nine " 
   NToL[10, 1] := "Ten " 
   NToL[11, 1] := "Eleven "
   NToL[12, 1] := "Twelve "
   NToL[13, 1] := "Thirteen "
   NToL[14, 1] := "Fourteen "
   NToL[15, 1] := "Fifteen "
   NToL[16, 1] := "Sixteen "
   NToL[17, 1] := "Seventeen "
   NToL[18, 1] := "Eighteen "
   NToL[19, 1] := "Nineteen "
   NToL[20, 1] := "Twenty "
   NToL[21, 1] := "Thirty "
   NToL[22, 1] := "Forty "
   NToL[23, 1] := "Fifty "
   NToL[24, 1] := "Sixty "
   NToL[25, 1] := "Seventy "
   NToL[26, 1] := "Eighty "
   NToL[27, 1] := "Ninety "
   NToL[28, 1] := "Hundred "
   NToL[29, 1] := "Thousand "
    
 
    
   *****Millions*******

   nAmountL1    = Substr(Transform(nAmount, "9999999.99"), 1, 7)
   nAmountL2    = Substr(nAmountL1, 1, 1)

   nAmountL = IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                   IF(Val(nAmountL2) > 1, "Millions ", "Million "), "")

   *****Hundreds of thousands*********

   nAmountL2    = Substr(nAmountL1, 2, 1)
   nAmountL3    = Substr(nAmountL1, 3, 2)

   nAmountL = nAmountL + IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                            NToL[28, 1] + IF(Val(nAmountL3) > 0,;
                            "", NToL[29, 1]), "")


   *****Tenths of thousands*********

   nAmountL2    = Substr(nAmountL1, 3, 2)
   nAmountL3    = Substr(nAmountL1, 3, 1) 
   nAmountL4    = Substr(nAmountL1, 4, 1)
   nAmountL5    = Substr(nAmountL1, 2, 1)

   nAmountL = nAmountL + IF(Val(nAmountL2) < 20 .AND. Val(nAmountL2) > 0,;
                                NToL[Val(nAmountL2), 1] + NToL[29, 1], "")

   nAmountL = nAmountL + IF(Val(nAmountL2) > 19, NToL[(18 + ;
                                Val(nAmountL3)), 1] + IF(Val(nAmountL4) > 0,;
                                NToL[Val(nAmountL4), 1], "") + NToL[29, 1], "")
   
   *****Hundreds*********

   nAmountL2    = Substr(nAmountL1, 5, 1)
   nAmountL3    = Substr(nAmountL1, 6, 2) 

   nAmountL = nAmountL + IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                                NToL[28, 1], "")


   *****Tenths*********

   nAmountL2    = Substr(nAmountL1, 6, 2)
   nAmountL3    = Substr(nAmountL1, 6, 1) 
   nAmountL4    = Substr(nAmountL1, 7, 1)

   nAmountL = nAmountL + IF(Val(nAmountL2) < 20 .AND. Val(nAmountL2) > 0,;
                                NToL[Val(nAmountL2), 1], "")

   nAmountL = nAmountL + IF(Val(nAmountL2) > 19, NToL[(18 + ;
                                Val(nAmountL3)), 1] + IF(Val(nAmountL4) > 0,;
                                NToL[Val(nAmountL4), 1], ""), "")
    
   nAmountL = nAmountL + "Dollars and " + Substr(Transform(nAmount, "9999999.99"), -2) + " Cts."  
   
Return nAmountL  
 

Re: numeros a letras en ingles..

Posted: Thu Jan 10, 2013 5:29 am
by Bayron
Ejemplo completo probado con FiveWin for Harbour 12.04

Code: Select all

/*          Author:    Bayron Landaverry
                       Maya Point Of Sale
                       6 Av. 3-26, zona 4
                       Chiquimula, Guatemala


            Version:   Clipper 5.3 (But it may run on other
                                    versions with only a few
                                    changes, I think it may, anyway)


            Comments:   Does not need external library's

                        Does not have color nor graphics, for
                        compatibility with your applications.

                        There is no guarantee on this application.

                        It can be used and distributed freely.

                        Please feel free to modify it.
*/

#INCLUDE "FiveWin.CH"

Function main()
Local nAmount := 0

MsgGet("Cantidad",,@nAmount)

Msginfo( ALLTRIM( STR(nAmount) ) + ":=" +NumToLet(nAmount) )

Return NIL


FUNCTION NumToLet(nAmount)
   LOCAL NToL[29, 1]
    
   NToL[ 1, 1] := "One " 
   NToL[ 2, 1] := "Two " 
   NToL[ 3, 1] := "Three "
   NToL[ 4, 1] := "Four " 
   NToL[ 5, 1] := "Five " 
   NToL[ 6, 1] := "Six " 
   NToL[ 7, 1] := "Seven " 
   NToL[ 8, 1] := "Eight " 
   NToL[ 9, 1] := "Nine " 
   NToL[10, 1] := "Ten " 
   NToL[11, 1] := "Eleven "
   NToL[12, 1] := "Twelve "
   NToL[13, 1] := "Thirteen "
   NToL[14, 1] := "Fourteen "
   NToL[15, 1] := "Fifteen "
   NToL[16, 1] := "Sixteen "
   NToL[17, 1] := "Seventeen "
   NToL[18, 1] := "Eighteen "
   NToL[19, 1] := "Nineteen "
   NToL[20, 1] := "Twenty "
   NToL[21, 1] := "Thirty "
   NToL[22, 1] := "Forty "
   NToL[23, 1] := "Fifty "
   NToL[24, 1] := "Sixty "
   NToL[25, 1] := "Seventy "
   NToL[26, 1] := "Eighty "
   NToL[27, 1] := "Ninety "
   NToL[28, 1] := "Hundred "
   NToL[29, 1] := "Thousand "
    
 
    
   *****Millions*******

   nAmountL1    = Substr(Transform(nAmount, "9999999.99"), 1, 7)
   nAmountL2    = Substr(nAmountL1, 1, 1)

   nAmountL = IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                   IF(Val(nAmountL2) > 1, "Millions ", "Million "), "")

   *****Hundreds of thousands*********

   nAmountL2    = Substr(nAmountL1, 2, 1)
   nAmountL3    = Substr(nAmountL1, 3, 2)

   nAmountL = nAmountL + IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                            NToL[28, 1] + IF(Val(nAmountL3) > 0,;
                            "", NToL[29, 1]), "")


   *****Tenths of thousands*********

   nAmountL2    = Substr(nAmountL1, 3, 2)
   nAmountL3    = Substr(nAmountL1, 3, 1) 
   nAmountL4    = Substr(nAmountL1, 4, 1)
   nAmountL5    = Substr(nAmountL1, 2, 1)

   nAmountL = nAmountL + IF(Val(nAmountL2) < 20 .AND. Val(nAmountL2) > 0,;
                                NToL[Val(nAmountL2), 1] + NToL[29, 1], "")

   nAmountL = nAmountL + IF(Val(nAmountL2) > 19, NToL[(18 + ;
                                Val(nAmountL3)), 1] + IF(Val(nAmountL4) > 0,;
                                NToL[Val(nAmountL4), 1], "") + NToL[29, 1], "")
   
   *****Hundreds*********

   nAmountL2    = Substr(nAmountL1, 5, 1)
   nAmountL3    = Substr(nAmountL1, 6, 2) 

   nAmountL = nAmountL + IF(Val(nAmountL2) > 0, NToL[Val(nAmountL2), 1] +;
                                NToL[28, 1], "")


   *****Tenths*********

   nAmountL2    = Substr(nAmountL1, 6, 2)
   nAmountL3    = Substr(nAmountL1, 6, 1) 
   nAmountL4    = Substr(nAmountL1, 7, 1)

   nAmountL = nAmountL + IF(Val(nAmountL2) < 20 .AND. Val(nAmountL2) > 0,;
                                NToL[Val(nAmountL2), 1], "")

   nAmountL = nAmountL + IF(Val(nAmountL2) > 19, NToL[(18 + ;
                                Val(nAmountL3)), 1] + IF(Val(nAmountL4) > 0,;
                                NToL[Val(nAmountL4), 1], ""), "")
    
   nAmountL = nAmountL + IF(nAmount > 1, "Dollars ", "Dollar " ) + "and " + Substr(Transform(nAmount, "9999999.99"), -2) + " Cts."  
   
   nAmountL = IF( nAmount <= 0, "Zero Dollars", nAmountL )
   
Return nAmountL