Accueil > > > DES NOMBRES EN TOUTES LETTRES (JUSQU'À 999 999 999 999,999 999 999 99)
DES NOMBRES EN TOUTES LETTRES (JUSQU'À 999 999 999 999,999 999 999 99)
Information sur la source
Description
Ecrire un nombre en français, je sais, c'est du déjà vu mais : - on va jusqu'à 999 999 999 999,999 999 999 99 mais rien n'empêche de supprimer des lignes de code pour limiter - la sortie est en français, sans faute d'orthographe - c'est un exemple de fonction récursive (elle s'appelle elle-même) Appel de la fonction par : Print Nombre_en_lettres(123.7845) qui donne : cent vingt trois unités sept mille huit cent quarante cinq dix-millièmes
Source
- Public Function Francise(ByVal nb As String) As String
- Do While Left(nb, 1) = "0"
- If Left(nb, 1) = "0" Then nb = Mid(nb, 2) 'suppression des zéros à gauche
- Loop
- Select Case Len(nb)
- Case 0
- Francise = ""
- Case 1
- Select Case nb
- Case "0": Francise = "zéro"
- Case "1": Francise = "un"
- Case "2": Francise = "deux"
- Case "3": Francise = "trois"
- Case "4": Francise = "quatre"
- Case "5": Francise = "cinq"
- Case "6": Francise = "six"
- Case "7": Francise = "sept"
- Case "8": Francise = "huit"
- Case "9": Francise = "neuf"
- End Select
- Case 2
- Select Case nb
- Case "10": Francise = "dix"
- Case "11": Francise = "onze"
- Case "12": Francise = "douze"
- Case "13": Francise = "treize"
- Case "14": Francise = "quatorze"
- Case "15": Francise = "quinze"
- Case "16": Francise = "seize"
- Case "17" To "19": Francise = "dix " & Francise(Right(nb, 1))
- Case "20" To "29": Francise = "vingt " & Francise(Right(nb, 1))
- Case "30" To "39": Francise = "trente " & Francise(Right(nb, 1))
- Case "40" To "49": Francise = "quarante " & Francise(Right(nb, 1))
- Case "50" To "59": Francise = "cinquante " & Francise(Right(nb, 1))
- Case "60" To "69": Francise = "soixante " & Francise(Right(nb, 1))
- Case "70" To "79"
- nb = Format(Val(nb) - 60, "##")
- Francise = "soixante " & Francise(nb)
- If Right(Francise, 4) = "onze" Then Francise = "soixante et onze"
- Case "80": Francise = "quatre-vingts"
- Case "81" To "99"
- nb = Format(Val(nb) - 80, "##")
- Francise = "quatre-vingt " & Francise(nb)
- End Select
- If Right(Francise, 2) = "un" And nb > "20" And nb < 70 Then Francise = Left(Francise, Len(Francise) - 2) & "et un"
-
- If Right(Francise, 4) = "zéro" Then Francise = Left(Francise, Len(Francise) - 5)
- Case 3
- Select Case Left(nb, 1)
- Case "1": Francise = "cent " & Francise(Mid(nb, 2))
- Case Else
- Francise = Francise(Left(nb, 1)) & " cent " & Francise(Mid(nb, 2))
- If Right(Francise, 6) = " cent " Then Francise = Left(Francise, Len(Francise) - 1) & "s"
- End Select
- Case 4 To 6
- Francise = Francise(Left(nb, Len(nb) - 3)) & " mille " & Francise(Right(nb, 3))
- If Left(Francise, 2) = "un" Then Francise = Mid(Francise, 4)
- Case 7 To 9
- Francise = Francise(Left(nb, Len(nb) - 6)) & " millions " & Francise(Right(nb, 6))
- If Left(Francise, 2) = "un" Then Francise = Left(Francise, 10) & Mid(Francise, 12)
- Case 10 To 12
- Francise = Francise(Left(nb, Len(nb) - 9)) & " milliards " & Francise(Right(nb, 9))
- If Left(Francise, 2) = "un" Then Francise = Left(Francise, 11) & Mid(Francise, 13)
- Case Else
- End Select
- End Function
- '-------------------------------------------------------------------
- Public Function Nombre_en_lettres(ByVal nb As String) As String
- Dim Affichage As String, Entier As String, Décimal As String
- nb = Replace(nb, ".", ",")
- If Not IsNumeric(nb) Then
- MsgBox Form1.Text1.Text & " n'est pas un nombre", vbCritical, Erreur
- Exit Function
- End If
- If InStr(nb, ",") = 0 Then 'c'est un entier
- Affichage = Francise(nb)
- Else 'c'est un décimal
- Do While Right(nb, 1) = "0" 'suppression des zéros à droite de la partie décimale
- If Right(nb, 1) = "0" Then nb = Left(nb, Len(nb) - 1)
- Loop
- Entier = Francise(Left(nb, InStr(nb, ",") - 1))
- If Right(Entier, 2) = "un" Then Entier = Entier & "e"
- If Entier = "une" Then
- Entier = Entier & " unité "
- Else
- If Entier <> "" Then
- Entier = Entier & " unités "
- End If
- End If
- Décimal = Francise(Mid(nb, InStr(nb, ",") + 1))
- Affichage = Entier & Décimal & " "
- Select Case Len(Mid(nb, InStr(nb, ",") + 1))
- Case 1: Affichage = Affichage & "dixième"
- Case 2: Affichage = Affichage & "centième"
- Case 3: Affichage = Affichage & "millième"
- Case 4: Affichage = Affichage & "dix-millième"
- Case 5: Affichage = Affichage & "cent-millième"
- Case 6: Affichage = Affichage & "millionième"
- Case 7: Affichage = Affichage & "dix-millionième"
- Case 8: Affichage = Affichage & "cent-millionième"
- Case 9: Affichage = Affichage & "milliardième"
- Case 10: Affichage = Affichage & "dix-milliardième"
- Case 11: Affichage = Affichage & "cent-milliardième"
- End Select
- If Décimal <> "un" Then Affichage = Affichage & "s"
- End If
- Nombre_en_lettres = Affichage' retour fonction
- End Function
-
Public Function Francise(ByVal nb As String) As String
Do While Left(nb, 1) = "0"
If Left(nb, 1) = "0" Then nb = Mid(nb, 2) 'suppression des zéros à gauche
Loop
Select Case Len(nb)
Case 0
Francise = ""
Case 1
Select Case nb
Case "0": Francise = "zéro"
Case "1": Francise = "un"
Case "2": Francise = "deux"
Case "3": Francise = "trois"
Case "4": Francise = "quatre"
Case "5": Francise = "cinq"
Case "6": Francise = "six"
Case "7": Francise = "sept"
Case "8": Francise = "huit"
Case "9": Francise = "neuf"
End Select
Case 2
Select Case nb
Case "10": Francise = "dix"
Case "11": Francise = "onze"
Case "12": Francise = "douze"
Case "13": Francise = "treize"
Case "14": Francise = "quatorze"
Case "15": Francise = "quinze"
Case "16": Francise = "seize"
Case "17" To "19": Francise = "dix " & Francise(Right(nb, 1))
Case "20" To "29": Francise = "vingt " & Francise(Right(nb, 1))
Case "30" To "39": Francise = "trente " & Francise(Right(nb, 1))
Case "40" To "49": Francise = "quarante " & Francise(Right(nb, 1))
Case "50" To "59": Francise = "cinquante " & Francise(Right(nb, 1))
Case "60" To "69": Francise = "soixante " & Francise(Right(nb, 1))
Case "70" To "79"
nb = Format(Val(nb) - 60, "##")
Francise = "soixante " & Francise(nb)
If Right(Francise, 4) = "onze" Then Francise = "soixante et onze"
Case "80": Francise = "quatre-vingts"
Case "81" To "99"
nb = Format(Val(nb) - 80, "##")
Francise = "quatre-vingt " & Francise(nb)
End Select
If Right(Francise, 2) = "un" And nb > "20" And nb < 70 Then Francise = Left(Francise, Len(Francise) - 2) & "et un"
If Right(Francise, 4) = "zéro" Then Francise = Left(Francise, Len(Francise) - 5)
Case 3
Select Case Left(nb, 1)
Case "1": Francise = "cent " & Francise(Mid(nb, 2))
Case Else
Francise = Francise(Left(nb, 1)) & " cent " & Francise(Mid(nb, 2))
If Right(Francise, 6) = " cent " Then Francise = Left(Francise, Len(Francise) - 1) & "s"
End Select
Case 4 To 6
Francise = Francise(Left(nb, Len(nb) - 3)) & " mille " & Francise(Right(nb, 3))
If Left(Francise, 2) = "un" Then Francise = Mid(Francise, 4)
Case 7 To 9
Francise = Francise(Left(nb, Len(nb) - 6)) & " millions " & Francise(Right(nb, 6))
If Left(Francise, 2) = "un" Then Francise = Left(Francise, 10) & Mid(Francise, 12)
Case 10 To 12
Francise = Francise(Left(nb, Len(nb) - 9)) & " milliards " & Francise(Right(nb, 9))
If Left(Francise, 2) = "un" Then Francise = Left(Francise, 11) & Mid(Francise, 13)
Case Else
End Select
End Function
'-------------------------------------------------------------------
Public Function Nombre_en_lettres(ByVal nb As String) As String
Dim Affichage As String, Entier As String, Décimal As String
nb = Replace(nb, ".", ",")
If Not IsNumeric(nb) Then
MsgBox Form1.Text1.Text & " n'est pas un nombre", vbCritical, Erreur
Exit Function
End If
If InStr(nb, ",") = 0 Then 'c'est un entier
Affichage = Francise(nb)
Else 'c'est un décimal
Do While Right(nb, 1) = "0" 'suppression des zéros à droite de la partie décimale
If Right(nb, 1) = "0" Then nb = Left(nb, Len(nb) - 1)
Loop
Entier = Francise(Left(nb, InStr(nb, ",") - 1))
If Right(Entier, 2) = "un" Then Entier = Entier & "e"
If Entier = "une" Then
Entier = Entier & " unité "
Else
If Entier <> "" Then
Entier = Entier & " unités "
End If
End If
Décimal = Francise(Mid(nb, InStr(nb, ",") + 1))
Affichage = Entier & Décimal & " "
Select Case Len(Mid(nb, InStr(nb, ",") + 1))
Case 1: Affichage = Affichage & "dixième"
Case 2: Affichage = Affichage & "centième"
Case 3: Affichage = Affichage & "millième"
Case 4: Affichage = Affichage & "dix-millième"
Case 5: Affichage = Affichage & "cent-millième"
Case 6: Affichage = Affichage & "millionième"
Case 7: Affichage = Affichage & "dix-millionième"
Case 8: Affichage = Affichage & "cent-millionième"
Case 9: Affichage = Affichage & "milliardième"
Case 10: Affichage = Affichage & "dix-milliardième"
Case 11: Affichage = Affichage & "cent-milliardième"
End Select
If Décimal <> "un" Then Affichage = Affichage & "s"
End If
Nombre_en_lettres = Affichage' retour fonction
End Function
Conclusion
Dois-je vraiment le mettre dans la catégorie maths ?
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|