CONVERSION MULTI-LANGUE DE NOMBRES EN TEXTE

ImmoAssist Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 20 février 2006 - 9 août 2005 à 19:37
DrJo45 Messages postés 16 Date d'inscription vendredi 7 novembre 2003 Statut Membre Dernière intervention 23 juin 2006 - 29 août 2005 à 09:25
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/33157-conversion-multi-langue-de-nombres-en-texte

DrJo45 Messages postés 16 Date d'inscription vendredi 7 novembre 2003 Statut Membre Dernière intervention 23 juin 2006
29 août 2005 à 09:25
Malgré les quelques problèmes déjà cités en français (d'autres source sur le site proposent des solutions les corrigeant), on peut quand même dire bravo pour l'idée. Il semble en tout cas que le français soit vraiment le plus difficile pour ce problème; les autres langues ne présentant pas autant d'exceptions. Le multilingue est particulièrement utile ici où un simple dictionnaire ne suffit pas !
Je cherchais justement cela.
Merci.
Cacophrene Messages postés 251 Date d'inscription lundi 29 mars 2004 Statut Membre Dernière intervention 4 mars 2008 1
13 août 2005 à 15:44
ERREUR DANS MON TEXTE

Second paragraphe :
Deuxièmement, si je demande NumberToTextFrench(1238465), j'obtiens "quatre-vingt" et non pas "quatre-vingts" qui est l'écriture correcte (manquant : le s de la règle de grammaire de vingt et cent, d'où ; pareil avec NumberToTextFrench(200) qui donne "Deux cent" et non pas "Deux cents").

Merci de lire :
Deuxièmement, si je demande NumberToTextFrench(80), j'obtiens "quatre-vingt" et non pas "quatre-vingts" qui est l'écriture correcte (manquant : le s de la règle de grammaire de vingt et cent, d'où ; pareil avec NumberToTextFrench(200) qui donne "Deux cent" et non pas "Deux cents").
Cacophrene Messages postés 251 Date d'inscription lundi 29 mars 2004 Statut Membre Dernière intervention 4 mars 2008 1
13 août 2005 à 15:10
Salut !

Il y avait déjà de telles sources sur le site, mais il est vrai monolingues. La force de celle-ci, c'est de proposer une conversion dans plusieurs langues. CEPENDANT, il y a plusieurs problèmes au niveau du français.

Lorsque je demande NumberToTextFrench(1238465), j'obtiens : "Million deux cent trente huit mille quatre cent soixante cinq", alors que la chaîne correcte est : "un million deux cent trente-huit mille quatre cent soixante-cinq" (manquants : "un" antéposé et traits d'union)

Deuxièmement, si je demande NumberToTextFrench(1238465), j'obtiens "quatre-vingt" et non pas "quatre-vingts" qui est l'écriture correcte (manquant : le s de la règle de grammaire de vingt et cent, d'où ; pareil avec NumberToTextFrench(200) qui donne "Deux cent" et non pas "Deux cents").

Côté programmation, il y a peu de commentaires, ce qui est un peu dommage car, même facile, ce code est long. Moi je mets 7.

Cordialement,
Cacophrène
ImmoAssist Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 20 février 2006
10 août 2005 à 10:33
Dutch = Néerlandais

Pour le zip, on pourrait le faire après

Voici la version portuguese

Public Function NumberToTextPortuguese(sValue As String) As String
' #VBIDEUtils#************************************************************
' * Author : Waty Thierry
' * Web Site : http://www.vbdiamond.com
' * E-Mail : waty.thierry@vbdiamond.com
' * Date : 08/08/2005
' * Time : 18:13
' * Module Name : Lib_Module
' * Module Filename : Lib.bas
' * Procedure Name : NumberToTextPortuguese
' * Purpose :
' * Parameters :
' * sValue As String
' * Purpose :
' **********************************************************************
' * Comments :
' *
' *
' * Example :
' *
' * See Also :
' *
' * History :
' *
' *
' **********************************************************************

' #VBIDEUtilsERROR#
On Error GoTo ERROR_NumberToTextPortuguese

Dim n(900) As String
Dim MOEDA As String
Dim Numero As Double

n(1) = "um "
n(2) = "dois "
n(3) = "tres "
n(4) = "quatro "
n(5) = "cinco "
n(6) = "seis "
n(7) = "sete "
n(8) = "oito "
n(9) = "nove "
n(10) = "dez "
n(11) = "onze "
n(12) = "doze "
n(13) = "treze "
n(14) = "quatorze "
n(15) = "quinze "
n(16) = "dezesseis "
n(17) = "dezessete "
n(18) = "dezoito "
n(19) = "dezenove "
n(20) = "vinte "
n(30) = "trinta "
n(40) = "quarenta "
n(50) = "cinquenta "
n(60) = "sessenta "
n(70) = "setenta "
n(80) = "oitenta "
n(90) = "noventa "
n(100) = "cem "
n(200) = "duzentos "
n(300) = "trezentos "
n(400) = "quatrocentos "
n(500) = "quinhentos "
n(600) = "seiscentos "
n(700) = "setecentos "
n(800) = "oitocentos "
n(900) = "novecentos "
MOEDA = vbNullString

NumberToTextPortuguese = vbNullString

sValue = Replace(sValue, " ", vbNullString)
If IsNumeric(sValue) = False Then Exit Function

' *** MILHOES
Numero = Int((sValue / 1000000))
If Numero > 0 Then
MOEDA = "de reais "
' *** CENTENA DE MILHOES
If Numero > 99 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 100 Then
If Int(Numero / 100) = 1 Then
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & "cem "
Else
NumberToTextPortuguese = NumberToTextPortuguese & "cento e "
End If
Else
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100) & "e "
End If
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
End If
End If

' *** DEZENA DE MILHOES
Numero = Numero - (Int(Numero / 100) * 100)
If Numero > 9 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 10 Then
If Numero - (Int(Numero / 10) * 10) = 0 Or (Numero > 10 And Numero < 20) Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 10) * 10) & "e "
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If

' *** UNIDADE DE MILHOES
If Numero < 10 Or Numero > 19 Then
Numero = Numero - (Int(Numero / 10) * 10)
If Numero > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If
If Numero = 1 Then
NumberToTextPortuguese = NumberToTextPortuguese & "milhão "
Else
NumberToTextPortuguese = NumberToTextPortuguese & "milhão "
End If
End If

' *** MILHARES
Numero = Int((sValue / 1000)) - (Int((sValue / 1000000)) * 1000)

If Numero > 0 Then
MOEDA = "reais "
' *** CENTENA DE MILHARES
If Numero > 99 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 100 Then
If Int(Numero / 100) = 1 Then
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & "cem "
Else
NumberToTextPortuguese = NumberToTextPortuguese & "cento e "
End If
Else
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100) & "e "
End If
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
End If
End If

' *** DEZENA DE MILHARES
Numero = Numero - (Int(Numero / 100) * 100)
If Numero > 9 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 10 Then
If Numero - (Int(Numero / 10) * 10) = 0 Or (Numero > 10 And Numero < 20) Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 10) * 10) & "e "
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If

' *** UNIDADE DE MILHARES
If Numero < 10 Or Numero > 19 Then
Numero = Numero - (Int(Numero / 10) * 10)
If Numero > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If
NumberToTextPortuguese = NumberToTextPortuguese & "mil"

End If

Numero = Int(sValue)

' *** CENTENAS
Numero = Int(sValue) - Int(sValue / 1000000) * 1000000
Numero = Int(sValue) - Int(sValue / 1000) * 1000

If Numero > 0 Then
If Len(NumberToTextPortuguese) > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & "e "
End If
MOEDA = "reais "
' *** CENTENA
If Numero > 99 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 100 Then
If Int(Numero / 100) = 1 Then
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & "cem "
Else
NumberToTextPortuguese = NumberToTextPortuguese & "cento e "
End If
Else
If Numero - (Int(Numero / 100) * 100) = 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100) & "e "
End If
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 100) * 100)
End If
End If

' *** DEZENA
Numero = Numero - (Int(Numero / 100) * 100)
If Numero > 9 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 10 Then
If Numero - (Int(Numero / 10) * 10) = 0 Or (Numero > 10 And Numero < 20) Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 10) * 10) & "e "
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If

' *** UNIDADE
If Numero < 10 Or Numero > 19 Then
Numero = Numero - (Int(Numero / 10) * 10)
If Numero > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If

End If

If sValue = 1 Then
NumberToTextPortuguese = NumberToTextPortuguese & "real "
Else
NumberToTextPortuguese = NumberToTextPortuguese & MOEDA
End If

' *** CENTAVOS
Numero = Int(Round(sValue - Int(sValue), 2) * 100)

If Numero > 0 Then
If Len(NumberToTextPortuguese) > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & "e "
End If
' *** DEZENA
Numero = Numero - (Int(Numero / 100) * 100)
If Numero > 9 Then

' *** VERIFICA SE TEM A LETRA "E"
If Numero > 10 Then
If Numero - (Int(Numero / 10) * 10) = 0 Or (Numero > 10 And Numero < 20) Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Int(Numero / 10) * 10) & "e "
End If
Else
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If

' *** UNIDADE
If Numero < 10 Or Numero > 19 Then
Numero = Numero - (Int(Numero / 10) * 10)
If Numero > 0 Then
NumberToTextPortuguese = NumberToTextPortuguese & n(Numero)
End If
End If
If Numero = 1 Then
NumberToTextPortuguese = NumberToTextPortuguese & "centavo"
Else
NumberToTextPortuguese = NumberToTextPortuguese & "centavos "
End If

End If

EXIT_NumberToTextPortuguese:
NumberToTextPortuguese = UCase(Left$(NumberToTextPortuguese, 1)) & Mid(NumberToTextPortuguese, 2)
Exit Function

' #VBIDEUtilsERROR#
ERROR_NumberToTextPortuguese:

End Function
BZY1 Messages postés 214 Date d'inscription jeudi 10 mars 2005 Statut Membre Dernière intervention 12 avril 2008
10 août 2005 à 09:46
c'est une tès bonne idée je trouve et le programme est clair
bouv Messages postés 1411 Date d'inscription mercredi 6 août 2003 Statut Membre Dernière intervention 3 mars 2019 1
10 août 2005 à 08:54
Les allemands ne mettent vraiment pas d'espaces entre les mots comme ça ?

Sinon un zip aurait été le bienvenue.
Et "Un Million deux ..." serait mieux que "Million deux ...".

Bon courage pour la suite
++
ImmoAssist Messages postés 12 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 20 février 2006
9 août 2005 à 19:37
Postez vos commentaires, et éventuellement dans d'autres langues, je vais continuer à poster pour d'autres langues que je fais pour le moment.
Rejoignez-nous