Função Valores em Extenso em Inglês

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

joaoalpande
Usuário Nível 2
Usuário Nível 2
Mensagens: 93
Registrado em: 24 Fev 2005 09:04
Localização: CAMPO GRANDE / MS

Função Valores em Extenso em Inglês

Mensagem por joaoalpande »

Boa Tarde,

Alguém tem a função para converter valores em extenso em inglês?

Cumprimentos

João Alpande
Kapiaba
Colaborador
Colaborador
Mensagens: 1908
Registrado em: 07 Dez 2012 16:14
Localização: São Paulo
Contato:

Função Valores em Extenso em Inglês

Mensagem por Kapiaba »

Código: Selecionar todos

/* 
* File......: NTOW.PRG 
* Author....: Gary Baren 
* CIS ID....: 75470,1027 
* 
* This is an original work by Gary Baren and is hereby placed in the 
* public domain. 
* 
* Modification history: 
* --------------------- 
* 
* Rev 1.1 15 Aug 1991 23:05:54 GLENN 
* Forest Belt proofread/edited/cleaned up doc 
* 
* Rev 1.0 09 Jun 1991 00:26:56 GLENN 
* Initial revision. 
* 
*/ 


/* $DOC$ 
* $FUNCNAME$ 
* FT_NTOW() 
* $CATEGORY$ 
* Conversion 
* $ONELINER$ 
* Translate numeric value to words 
* $SYNTAX$ 
* FT_NTOW( <nNumber> ) -> cWords 
* $ARGUMENTS$ 
* <nNumber> An integer to translate 
* $RETURNS$ 
* A text string representing <nNumber> 
* $DESCRIPTION$ 
* Translates numeric input to a text string. 
* 
* FT_NTOW is intended to be used with integers only. Since I don't 
* know what your application will be, I can't assume the type of 
* fraction you want returned (ninety nine cents, 99/100, .99, etc). 
* If you want the fraction in words, just pass it as an integer. 
* 
* Do not pass a negative number! Handle negative numbers any way 
* you need to in your code. (ie: CR, DB, Negative, Minus, etc.) 
* 
* Also, numeric 0 is returned as a null string. You will need to 
* make a decision how to output it (zero dollars, no dollars, etc). 
* $EXAMPLES$ 
* ? FT_NTOW( 999 ) -> Nine Hundred Ninety Nine 
* 
* ? FT_NTOW( 1000 ) -> One Thousand 
* 
* ? FT_NTOW( 23 ) + " Dollars and " + FT_NTOW( 99 ) + " Cents" 
* -> Twenty Three Dollars and Ninety Nine Cents 
* 
* ? FT_NTOW( 23 ) + " Dollars and " + "99/100" 
* -> Twenty Three Dollars and 99/100 
* 
* x := -23.99 
* cents := str( (x - int( x )) * 100, 2, 0 ) + "/100" 
* x := int( x ) 
* string := iif( x < 0, "Credit of ", "Debit of " ) 
* ? string + FT_NTOW( abs(x) ) + " Dollars and " + "99/100" 
* -> Credit of Twenty Three Dollars and 99/100 
* $END$ 
*/ 



static ones := { "", " One", " Two", " Three", " Four", " Five", ; 
                     " Six", " Seven", " Eight", " Nine" ;
               }

static teens := { " Ten", " Eleven", " Twelve", ; 
" Thirteen", " Fourteen", " Fifteen", ; 
" Sixteen", " Seventeen", " Eighteen", ; 
" Nineteen" ; 
} 

static tens := { "", "", " Twenty", " Thirty", " Forty", " Fifty", ; 
" Sixty", " Seventy", " Eighty", " Ninety" } 

static qualifiers := { "", " Thousand", " Million", " Billion", " Trillion" } 


#ifdef FT_TEST 
function main( cNum ) 
return qout( ft_ntow( val( cNum ) ) ) 
#endif 



function ft_ntow(nAmount) 
local nTemp, sResult := " ", nQualNo 
local nDiv := 10 ^ ( int( sol10(nAmount) / 3 ) * 3 ) 

nTemp := int(nAmount % nDiv) 
nAmount := int(nAmount / nDiv) 
nQualNo := int( sol10( nDiv ) / 3 ) + 1 
sResult += grp_to_words(nAmount, qualifiers[ nQualNo ] ) 

if nTemp > (nDiv /= 1000) .and. (nDiv > 1) 
sResult += ft_ntow( nTemp, nDiv ) 
else 
sResult += grp_to_words(nTemp, "") 
endif 
return( ltrim(sResult) ) 


static function grp_to_words(nGrp, sQual) 
local sResult := "", nTemp 

nTemp := int(nGrp % 100) 
nGrp := int(nGrp / 100) 
sResult += ones[ nGrp + 1 ] + iif( nGrp > 0, " Hundred", "") 

do case 
case nTemp > 19 
sResult += tens[ int( nTemp / 10 ) + 1 ] 
sResult += ones[ int( nTemp % 10 ) + 1 ] 
case nTemp < 20 .and. nTemp > 9 
sResult += teens[ int( nTemp % 10 ) + 1 ] 
case nTemp < 10 .and. nTemp > 0 
sResult += ones[ int( nTemp) + 1 ] 
endcase 
return(sResult + sQual) 


static function sol10( nNumber ) 
local sTemp 

sTemp := ltrim( str( int(nNumber), 0) ) 
return( len(sTemp) - 1 )
joaoalpande
Usuário Nível 2
Usuário Nível 2
Mensagens: 93
Registrado em: 24 Fev 2005 09:04
Localização: CAMPO GRANDE / MS

Função Valores em Extenso em Inglês

Mensagem por joaoalpande »

Boa Tarde,

Obrigado ,mas chegou a testar? eu já tentei testar essa função que vi no forum da fivetech e só deu o número inteiro , não deu os centimos, sera que fiz alguma coisa errada'

Cumprimentos
João Alpande
joaoalpande
Usuário Nível 2
Usuário Nível 2
Mensagens: 93
Registrado em: 24 Fev 2005 09:04
Localização: CAMPO GRANDE / MS

Função Valores em Extenso em Inglês

Mensagem por joaoalpande »

consigui meter os centimos em extenso, só tem um problema esta função,não coloca o - exemplo:
275.49
two hundred seventy-five euros and forty-nine cents

com esta função fica:

two hundred seventy five euros and forty nine cents


cumprmentos

João Alpande
joaoalpande
Usuário Nível 2
Usuário Nível 2
Mensagens: 93
Registrado em: 24 Fev 2005 09:04
Localização: CAMPO GRANDE / MS

Função Valores em Extenso em Inglês

Mensagem por joaoalpande »

Obrigado ,em português tenho a funcionar , só queria saber se alguém tinha essa função para inglês para não ter esse trabalho de adptar, mas se não tiver irei ter esse trabalho.

cumprimentos

João Alpande
Kapiaba
Colaborador
Colaborador
Mensagens: 1908
Registrado em: 07 Dez 2012 16:14
Localização: São Paulo
Contato:

Função Valores em Extenso em Inglês

Mensagem por Kapiaba »

Em fivewin:

http://forums.fivetechsupport.com/viewt ... s+a+letras

abraços.
Avatar do usuário
rochinha
Administrador
Administrador
Mensagens: 4664
Registrado em: 18 Ago 2003 20:43
Localização: São Paulo - Brasil
Contato:

Função Valores em Extenso em Inglês

Mensagem por rochinha »

Amiguinhos,

Na linha:

Código: Selecionar todos

...
static tens := { "", "", " Twenty", " Thirty", " Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety" }
Coloque assim:

Código: Selecionar todos

...
static tens := { "", "", " Twenty-", " Thirty-", " Forty-", " Fifty-", " Sixty-", " Seventy-", " Eighty-", " Ninety-" }
Nunca usei estas funções, na verdade tem muitas funções do Harbour que ainda não fiz uso.
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.

@braços : ? )

A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
Kapiaba
Colaborador
Colaborador
Mensagens: 1908
Registrado em: 07 Dez 2012 16:14
Localização: São Paulo
Contato:

Função Valores em Extenso em Inglês

Mensagem por Kapiaba »

Código: Selecionar todos

#include "FiveWin.ch"

/* 
* File......: NTOW.PRG 
* Author....: Gary Baren 
* CIS ID....: 75470,1027 
* 
* This is an original work by Gary Baren and is hereby placed in the 
* public domain. 
* 
* Modification history: 
* --------------------- 
* 
* Rev 1.1 15 Aug 1991 23:05:54 GLENN 
* Forest Belt proofread/edited/cleaned up doc 
* 
* Rev 1.0 09 Jun 1991 00:26:56 GLENN 
* Initial revision. 
* 
*/ 


/* $DOC$ 
* $FUNCNAME$ 
* FT_NTOW() 
* $CATEGORY$ 
* Conversion 
* $ONELINER$ 
* Translate numeric value to words 
* $SYNTAX$ 
* FT_NTOW( <nNumber> ) -> cWords 
* $ARGUMENTS$ 
* <nNumber> An integer to translate 
* $RETURNS$ 
* A text string representing <nNumber> 
* $DESCRIPTION$ 
* Translates numeric input to a text string. 
* 
* FT_NTOW is intended to be used with integers only. Since I don't 
* know what your application will be, I can't assume the type of 
* fraction you want returned (ninety nine cents, 99/100, .99, etc). 
* If you want the fraction in words, just pass it as an integer. 
* 
* Do not pass a negative number! Handle negative numbers any way 
* you need to in your code. (ie: CR, DB, Negative, Minus, etc.) 
* 
* Also, numeric 0 is returned as a null string. You will need to 
* make a decision how to output it (zero dollars, no dollars, etc). 
* $EXAMPLES$ 
* ? FT_NTOW( 999 ) -> Nine Hundred Ninety Nine
* 
* ? FT_NTOW( 1000 ) -> One Thousand
* 
* ? FT_NTOW( 23 ) + " Dollars and " + FT_NTOW( 99 ) + " Cents" 
* -> Twenty Three Dollars and Ninety Nine Cents 
* 
* ? FT_NTOW( 23 ) + " Dollars and " + "99/100" 
* -> Twenty Three Dollars and 99/100
* 
* x := -23.99 
* cents := str( (x - int( x )) * 100, 2, 0 ) + "/100" 
* x := int( x ) 
* string := iif( x < 0, "Credit of ", "Debit of " ) 
* ? string + FT_NTOW( abs(x) ) + " Dollars and " + "99/100" 
* -> Credit of Twenty Three Dollars and 99/100 
* $END$ 
*/ 

static ones := { "", " One", " Two", " Three", " Four", " Five", ; 
                     " Six", " Seven", " Eight", " Nine" ;
               }

static teens := { " Ten", " Eleven", " Twelve", ; 
                  " Thirteen", " Fourteen", " Fifteen", ;
                  " Sixteen", " Seventeen", " Eighteen", ;
                  " Nineteen" ;
                }

// Original
static tens := { "", "", " Twenty", " Thirty", " Forty", " Fifty", ; 
                         " Sixty", " Seventy", " Eighty", " Ninety" }

// By Rochinha  // Nao entendi, retorna extenso incorreto.
/*
static tens := { "", "", " Twenty-", " Thirty-", " Forty-", " Fifty-", ;
                         " Sixty-", " Seventy-", " Eighty-", " Ninety-" }
*/

static qualifiers := { "", " Thousand", " Million", " Billion", " Trillion" } 

Function Main() //main( cNum )


   ? FT_NTOW( 100 ) + " Dollars "

   ? FT_NTOW( 999 ) //-> Nine Hundred Ninety Nine

   ? FT_NTOW( 1000 ) + " Dollars " //-> One Thousand Dollars

   ? FT_NTOW( 23 ) + " Dollars and " + FT_NTOW( 99 ) + " Cents"
   * -> Twenty Three Dollars and Ninety Nine Cents

   ? FT_NTOW( 23 ) + " Dollars and " + "99/100"
   * -> Twenty Three Dollars and 99/100

Return Nil  // qout( ft_ntow( val( cNum ) ) )

function ft_ntow(nAmount)
 
   local nTemp, sResult := " ", nQualNo
   local nDiv := 10 ^ ( int( sol10(nAmount) / 3 ) * 3 )

   nTemp := int(nAmount % nDiv)

   nAmount := int(nAmount / nDiv)

   nQualNo := int( sol10( nDiv ) / 3 ) + 1

   sResult += grp_to_words(nAmount, qualifiers[ nQualNo ] ) 

   if nTemp > (nDiv /= 1000) .and. (nDiv > 1)

      sResult += ft_ntow( nTemp, nDiv )

   else

      sResult += grp_to_words(nTemp, "")

   endif

   //? ltrim(sResult)

return( ltrim(sResult) )

static function grp_to_words(nGrp, sQual)

   local sResult := "", nTemp

   nTemp := int(nGrp % 100)

   nGrp := int(nGrp / 100)

   sResult += ones[ nGrp + 1 ] + iif( nGrp > 0, " Hundred", "")

   do case
   case nTemp > 19

      sResult += tens[ int( nTemp / 10 ) + 1 ]

      sResult += ones[ int( nTemp % 10 ) + 1 ]

   case nTemp < 20 .and. nTemp > 9

      sResult += teens[ int( nTemp % 10 ) + 1 ]

   case nTemp < 10 .and. nTemp > 0

      sResult += ones[ int( nTemp) + 1 ]

   endcase

return(sResult + sQual) 

static function sol10( nNumber )
 
   local sTemp

   sTemp := ltrim( str( int(nNumber), 0) )

return( len(sTemp) - 1 )
abs,

Avatar do usuário
rochinha
Administrador
Administrador
Mensagens: 4664
Registrado em: 18 Ago 2003 20:43
Localização: São Paulo - Brasil
Contato:

Função Valores em Extenso em Inglês

Mensagem por rochinha »

Amiguinhos,

Óieu aqui traveiz.

Como havia indicado logo acima, de colocar o "-"(hifen) após o qualificador de moeda, e como havia dito nunca tinha usado a função e também porque o nobre colega João Santos frisou que não funcionou, fui fazer meus testes e conhecer a função e saber o que se podia fazer.

Bem na linha abaixo eu coloqui os hifens e percebi que causava um espaço extra na concatenação das palavras então:

Código: Selecionar todos

// By Rochinha  // Nao entendi, retorna extenso incorreto.
static tens := { "", "", " Twenty-", " Thirty-", " Forty-", " Fifty-", " Sixty-", " Seventy-", " Eighty-", " Ninety-" }
Habilitei a linha acima e na função FT_NTOW() adicionei funções ao retorno:

Código: Selecionar todos

return( strtran(ltrim(sResult),"- ","-") )
Nesta função eu saio em busca de hifen+espaço e troco por hifen somente.

Para mim, ficou saboroso.

Código: Selecionar todos

function ft_ntow(nAmount)
   local nTemp, sResult := " ", nQualNo
   local nDiv := 10 ^ ( int( sol10(nAmount) / 3 ) * 3 )
   nTemp := int(nAmount % nDiv)
   nAmount := int(nAmount / nDiv)
   nQualNo := int( sol10( nDiv ) / 3 ) + 1
   sResult += grp_to_words(nAmount, qualifiers[ nQualNo ] ) 
   if nTemp > (nDiv /= 1000) .and. (nDiv > 1)
      sResult += ft_ntow( nTemp, nDiv )
   else
      sResult += grp_to_words(nTemp, "")
   endif
   //? ltrim(sResult)
   return( strtran(ltrim(sResult),"- ","-") )
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.

@braços : ? )

A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
Avatar do usuário
rochinha
Administrador
Administrador
Mensagens: 4664
Registrado em: 18 Ago 2003 20:43
Localização: São Paulo - Brasil
Contato:

Função Valores em Extenso em Inglês

Mensagem por rochinha »

Amiguinhos,

Fiz uns testes com a Função FT_NTOW() achei interessante, mas como eu já tinha uma função preferi melhorá-la e disponibilizar na sessão Contribuições, Dicas e Tutoriais:

Segue os links da versão em BRasileiro e ENgles:

FUNÇÃO: Valores extensos até quatrilhão.

FUNÇÃO: Valores extensos até quatrilhão(ENgles).
OPS! LINK QUEBRADO? Veja ESTE TOPICO antes e caso não encontre ENVIE seu email com link do tópico para [url=mailto://fivolution@hotmail.com]fivolution@hotmail.com[/url]. Agradecido.

@braços : ? )

A justiça divina tarda mas não falha, enquanto que a justiça dos homens falha porque tarda.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Função Valores em Extenso em Inglês

Mensagem por JoséQuintas »

Se a rotina indicada funciona pra números, então basta usá-la duas vezes, uma pra inteiros e outra pra decimais.

Algo mais ou menos assim, mas tratando singular/plural e centavos zero.

Código: Selecionar todos

ft_NTow( Int( nValor ) ) + " DOLAR " + ft_NTow( nValor - Int( nValor ) )  + " CENTS"
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7929
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Função Valores em Extenso em Inglês

Mensagem por Itamar M. Lins Jr. »

O Viktor está antenado!
2014-07-24 13:41 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
* contrib/hbnf/ntow.prg
% and some more

2014-07-24 13:37 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
* contrib/hbnf/ntow.prg
% optimizations

2014-07-24 13:30 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
* contrib/hbnf/ntow.prg
! two fixes to prev

2014-07-24 13:15 UTC+0200 Viktor Szakats (vszakats users.noreply.github.com)
* contrib/hbnf/ntow.prg
! FT_NTOW() fixed original bug missing space separator between certain words
! FT_NTOW() fixed to use '-' instead of space separator between certain words
% minor cleanup
; f.e. try 14234325
Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Jairo Maia
Moderador
Moderador
Mensagens: 2785
Registrado em: 16 Ago 2010 13:46
Localização: Campinas-SP

Função Valores em Extenso em Inglês

Mensagem por Jairo Maia »

Since 2014-07-24 13:30, until 2014-07-24 13:41. Acho que ele acompanha este fórum. Tomara...
:-Y
Abraços, Jairo
Harbour / Clipper 5.2e - Blinker 7
(Não respondo dúvidas por MP ou E-mail. Por favor, não encaminhe via mensagem privada ou e-mail, dúvidas que podem ser compartilhadas com todos no fórum)
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Função Valores em Extenso em Inglês

Mensagem por JoséQuintas »

Este fórum está relacionado nos documentos do Harbour 3.4
Acredito que ele esteja acompanhando.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Responder