convertir des chiffres vers des lettre
convertir des chiffres vers des lettre
Est ce que vous avez un code deja fait ou est ce compliqué ?
-
- Messages : 1500
- Inscription : jeu. 25/mars/2004 11:23
- Localisation : Sophia Antipolis (Nice)
- Contact :
Str() ???
Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Participez à son extension: ajouter vos programmes et partagez vos codes !
lionel_om c'est un peu plus compliqué que ça 
il veut dire , enfin , si j'ai bien compris
transformer 123,56 € en cent vingt trois euros cinquante six centimes
Il existe plein de codes sur le net pour faire ça , une petite recherche avec google et tu en trouveras un paquet dans différents langages prêts à adapter
Je me demande si j'en ai pas vu un écrit en PureBasic d'ailleurs ?
J'ai vu quelqu'un qui bossait sur ce sujet sur le forum anglais , il cherchait à le faire dans différentes langues , je ne sais plus si les codes étaient dispos par contre.

il veut dire , enfin , si j'ai bien compris
transformer 123,56 € en cent vingt trois euros cinquante six centimes
Il existe plein de codes sur le net pour faire ça , une petite recherche avec google et tu en trouveras un paquet dans différents langages prêts à adapter

Je me demande si j'en ai pas vu un écrit en PureBasic d'ailleurs ?
J'ai vu quelqu'un qui bossait sur ce sujet sur le forum anglais , il cherchait à le faire dans différentes langues , je ne sais plus si les codes étaient dispos par contre.
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
-
- Messages : 1500
- Inscription : jeu. 25/mars/2004 11:23
- Localisation : Sophia Antipolis (Nice)
- Contact :
Bah en tout cas c'est des codes très faciles à faire.
Tu devrais t'en sortir facilement Julien
Tu devrais t'en sortir facilement Julien

Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Participez à son extension: ajouter vos programmes et partagez vos codes !
J'en ai trouvé un en VB, il faut que je l'adape mais je ne comprend pas tout, je recherche sur le net l'explication de comment faire pour pouvoir le mettre en pb
Code : Tout sélectionner
1. Public Function NversL(NversL_n As Double, NversL_entier As String, NversL_réél As String)
2.
3. '*** Auteur : Gilles PFOTZER (GIPP)
4. '*** http://www.chez.com/gipp/
5.
6. Dim NversL_n1 As Double
7. Dim NversL_n2 As Single
8. Dim NversL_t As String
9. Dim NversL_x As String
10.
11. NversL_n1 = NversL_n
12. NversL_t = ""
13.
14. 'Erreur
15. If NversL_n1 > 999999999.99 Then
16. NversL = "Erreur !"
17. Exit Function
18. End If
19.
20. 'Million
21. NversL_n2 = Int(NversL_n1 / 1000000)
22. NversL_x = NversL_cent(NversL_n2, False)
23. NversL_n1 = NversL_n1 - NversL_n2 * 1000000
24. If Trim(NversL_x) <> "zéro" Then
25. NversL_t = NversL_t & NversL_x & " million"
26. If Trim(NversL_x) <> "un" Then NversL_t = NversL_t & "s"
27.
28. 'Pour avoir 'un million [de] francs'
29. If Int(NversL_n1) = 0 Then NversL_t = NversL_t & " de"
30. End If
31.
32. 'Millier
33. NversL_n2 = Int(NversL_n1 / 1000)
34. NversL_x = NversL_cent(NversL_n2, True)
35. NversL_n1 = NversL_n1 - NversL_n2 * 1000
36. If Trim(NversL_x) <> "zéro" Then
37. If Trim(NversL_x) <> "un" Then
38. NversL_t = NversL_t & NversL_x & " mille"
39. Else
40. NversL_t = NversL_t & " mille"
41. End If
42. End If
43.
44. 'Unité
45. NversL_n2 = Int(NversL_n1)
46. NversL_x = NversL_cent(NversL_n2, False)
47. NversL_n1 = NversL_n1 - NversL_n2
48. If Trim(NversL_x) <> "zéro" Then NversL_t = NversL_t & NversL_x
49.
50. 'zéro
51. If Len(NversL_t) = 0 Then NversL_t = "zéro"
52.
53. 'Franc(s)
54. If NversL_entier <> "" Then NversL_t = NversL_t & " " & NversL_entier
55. If Int(NversL_n) > 1 And Trim(NversL_entier) <> "" Then NversL_t = NversL_t & "s"
56.
57. 'Dixième
58. NversL_n2 = CInt(NversL_n1 * 100)
59. NversL_x = NversL_cent(NversL_n2, False)
60. NversL_n1 = NversL_n1 - NversL_n2
61. If Trim(NversL_x) <> "zéro" Then
62. NversL_t = NversL_t & " et" & NversL_x & IIf(NversL_réél <> "", " " & NversL_réél, "")
63. If NversL_n2 > 1 And Trim(NversL_réél) <> "" Then NversL_t = NversL_t & "s"
64. End If
65. NversL_t = Trim(NversL_t)
66. NversL = UCase(Left(NversL_t, 1)) & Right(NversL_t, Len(NversL_t) - 1)
67.
68. End Function
69.
70. Private Function NversL_cent(n_cent As Single, mille_cent As Boolean)
71. 'mille_cent : 'oui' si sa correspond à un millier
72.
73. Dim n1_cent As Single
74. Dim n2_cent As Single
75. Dim t_cent As String
76. Dim x_cent As String
77.
78. n1_cent = n_cent
79. t_cent = ""
80.
81. 'Centaine
82. n2_cent = Int(n1_cent / 100)
83. x_cent = NversL_chiffre(n2_cent)
84. n1_cent = n1_cent - n2_cent * 100
85. If Trim(x_cent) <> "zéro" Then
86. If Trim(x_cent) <> "un" Then t_cent = t_cent & " " & x_cent
87. t_cent = t_cent & " cent"
88. If Trim(x_cent) <> "un" Then
89.
90. 'Pas de 's' s'il y a un nombre derrière la centaine
91. If n1_cent = 0 Then
92.
93. 'Pas de 's' s'il y a le mot 'mille' derrière la centaine
94. If Not mille_cent Then t_cent = t_cent & "s"
95. End If
96. End If
97. End If
98.
99. 'Dizaine
100. n2_cent = n1_cent
101. Select Case n2_cent
102. Case 0 To 9
103. x_cent = NversL_chiffre(n2_cent)
104. Case 10
105. x_cent = "dix"
106. Case 11
107. x_cent = "onze"
108. Case 12
109. x_cent = "douze"
110. Case 13
111. x_cent = "treize"
112. Case 14
113. x_cent = "quatorze"
114. Case 15
115. x_cent = "quinze"
116. Case 16
117. x_cent = "seize"
118. Case 17
119. x_cent = "dix-sept"
120. Case 18
121. x_cent = "dix-huit"
122. Case 19
123. x_cent = "dix-neuf"
124. Case 20
125. x_cent = "vingt"
126. Case 21
127. x_cent = "vingt et un"
128. Case 22 To 29
129. x_cent = "vingt-" & NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
130. Case 30
131. x_cent = "trente"
132. Case 31
133. x_cent = "trente et un"
134. Case 32 To 39
135. x_cent = "trente-" & NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
136. Case 40
137. x_cent = "quarante"
138. Case 41
139. x_cent = "quarante et un"
140. Case 42 To 49
141. x_cent = "quarante-" & NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
142. Case 50
143. x_cent = "cinquante"
144. Case 51
145. x_cent = "cinquante et un"
146. Case 52 To 59
147. x_cent = "cinquante-" & NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
148. Case 60
149. x_cent = "soixante"
150. Case 61
151. x_cent = "soixante et un"
152. Case 62 To 69
153. x_cent = "soixante-" & NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
154. Case 70
155. x_cent = "soixante-dix"
156. Case 71
157. x_cent = "soixante et onze"
158. Case 72 To 79
159. x_cent = "soixante-" & Trim(NversL_cent(n2_cent - 60, False))
160. Case 80
161. x_cent = "quatre-vingts"
162. Case 81 To 99
163. x_cent = "quatre-vingt-" & Trim(NversL_cent(n2_cent - 80, False))
164. End Select
165.
166. n1_cent = n1_cent - n2_cent
167.
168. 'Pour éviter 'cent zéro'
169. If Len(t_cent) = 0 Or Trim(x_cent) <> "zéro" Then t_cent = t_cent & " " & x_cent
170. NversL_cent = t_cent
171.
172. End Function
173.
174.
175. Private Function NversL_chiffre(n_chiffre As Single)
176.
177. Dim n1_chiffre As Single
178. Dim t_chiffre As String
179.
180. n1_chiffre = n_chiffre
181.
182. Select Case n1_chiffre
183. Case 0
184. t_chiffre = "zéro"
185. Case 1
186. t_chiffre = "un"
187. Case 2
188. t_chiffre = "deux"
189. Case 3
190. t_chiffre = "trois"
191. Case 4
192. t_chiffre = "quatre"
193. Case 5
194. t_chiffre = "cinq"
195. Case 6
196. t_chiffre = "six"
197. Case 7
198. t_chiffre = "sept"
199. Case 8
200. t_chiffre = "huit"
201. Case 9
202. t_chiffre = "neuf"
203. End Select
204.
205. NversL_chiffre = t_chiffre
206.
207. End Function
J'ai trouvé un début d'explication sur ces algo
Je regarderai ceci à tête rposé car ça a l'air dur,
http://yann.coscoy.free.fr/nombre/info.html
si vous avez des liens, je suis preneur
Je regarderai ceci à tête rposé car ça a l'air dur,
http://yann.coscoy.free.fr/nombre/info.html
si vous avez des liens, je suis preneur
-
- Messages : 1500
- Inscription : jeu. 25/mars/2004 11:23
- Localisation : Sophia Antipolis (Nice)
- Contact :
Ce qui donne (en PB) :
Par contre il y a des bugs :
190.25 => "Cent quatre-vingt-dixs et vingt-cinqs"
Code : Tout sélectionner
Declare.s NversL(NversL_n.f)
Declare.s NversL_cent(n_cent.l, mille_cent.b)
Declare.s NversL_chiffre(n_chiffre.l)
Procedure.s NversL(NversL_n.f)
Protected NversL_n1.f, NversL_n2.l
Protected NversL_t.s, NversL_x.s
NversL_n1 = NversL_n
NversL_t = ""
If NversL_n1 > 9999999.99
ProcedureReturn "Erreur !"
EndIf
;Million
NversL_n2 = Int(NversL_n1 / 1000000)
NversL_x = NversL_cent(NversL_n2, #False)
NversL_n1 = NversL_n1 - NversL_n2 * 1000000
If Trim(NversL_x) <> "zéro"
NversL_t = NversL_t + NversL_x + " million"
If Trim(NversL_x) <> "un"
NversL_t = NversL_t + "s"
EndIf
;Pour avoir 'un million [de] francs'
If Int(NversL_n1) = #Null
NversL_t = NversL_t + " de"
EndIf
EndIf
;Millier
NversL_n2 = Int(NversL_n1 / 1000)
NversL_x = NversL_cent(NversL_n2, #True)
NversL_n1 = NversL_n1 - NversL_n2 * 1000
If Trim(NversL_x) <> "zéro"
If Trim(NversL_x) <> "un"
NversL_t = NversL_t + NversL_x + " mille"
Else
NversL_t = NversL_t + " mille"
EndIf
EndIf
;Unité
NversL_n2 = Int(NversL_n1)
NversL_x = NversL_cent(NversL_n2, #False)
NversL_n1 = NversL_n1 - NversL_n2
If Trim(NversL_x) <> "zéro"
NversL_t = NversL_t + NversL_x
EndIf
;zéro
If Len(NversL_t) = 0
NversL_t = "zéro"
EndIf
;Franc(s)
If Int(NversL_n) > 1
NversL_t = NversL_t + "s"
EndIf
;Dixième
;NversL_n2 = CInt(NversL_n1 * 100)
NversL_n2 = Int(NversL_n1 * 100)
NversL_x = NversL_cent(NversL_n2, False)
NversL_n1 = NversL_n1 - NversL_n2
If Trim(NversL_x) <> "zéro" ; !!!!!!!!!!!!!!!!!!!!!!!!!
NversL_t = NversL_t + " et" + NversL_x
If NversL_n2 > 1
NversL_t = NversL_t + "s"
EndIf
EndIf
NversL_t = Trim(NversL_t)
ProcedureReturn UCase(Left(NversL_t, 1)) + Right(NversL_t, Len(NversL_t) - 1)
EndProcedure
Procedure.s NversL_cent(n_cent.l, mille_cent.b)
;mille_cent : 'oui' si sa correspond à un millier
Protected n1_cent.l, n2_cent.l
Protected t_cent.s, x_cent.s
n1_cent = n_cent
t_cent = ""
;Centaine
n2_cent = Int(n1_cent / 100)
x_cent = NversL_chiffre(n2_cent)
n1_cent = n1_cent - n2_cent * 100
If Trim(x_cent) <> "zéro"
If Trim(x_cent) <> "un"
t_cent = t_cent + " " + x_cent
EndIf
t_cent = t_cent + " cent"
If Trim(x_cent) <> "un"
;Pas de 's' s'il y a un nombre derrière la centaine
If n1_cent = 0
;Pas de 's' s'il y a le mot 'mille' derrière la centaine
If mille_cent = 0
t_cent = t_cent + "s"
EndIf
EndIf
EndIf
EndIf
;Dizaine
n2_cent = n1_cent
Select n2_cent
Case 10
x_cent = "dix"
Case 11
x_cent = "onze"
Case 12
x_cent = "douze"
Case 13
x_cent = "treize"
Case 14
x_cent = "quatorze"
Case 15
x_cent = "quinze"
Case 16
x_cent = "seize"
Case 17
x_cent = "dix-sept"
Case 18
x_cent = "dix-huit"
Case 19
x_cent = "dix-neuf"
Case 20
x_cent = "vingt"
Case 21
x_cent = "vingt et un"
Case 30
x_cent = "trente"
Case 31
x_cent = "trente et un"
Case 40
x_cent = "quarante"
Case 41
x_cent = "quarante et un"
Case 50
x_cent = "cinquante"
Case 51
x_cent = "cinquante et un"
Case 60
x_cent = "soixante"
Case 61
x_cent = "soixante et un"
Case 70
x_cent = "soixante-dix"
Case 71
x_cent = "soixante et onze"
Case 80
x_cent = "quatre-vingts"
Default
If n2_cent >=0 And n2_cent <= 9
x_cent = NversL_chiffre(n2_cent)
ElseIf n2_cent >=22 And n2_cent <= 29
x_cent = "vingt-" + NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
ElseIf n2_cent >=32 And n2_cent <= 39
x_cent = "trente-" + NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
ElseIf n2_cent >=42 And n2_cent <= 49
x_cent = "quarante-" + NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
ElseIf n2_cent >=52 And n2_cent <= 59
x_cent = "cinquante-" + NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
ElseIf n2_cent >=62 And n2_cent <= 69
x_cent = "soixante-" + NversL_chiffre(n2_cent - Int(n2_cent / 10) * 10)
ElseIf n2_cent >=72 And n2_cent <= 79
x_cent = "soixante-" + Trim(NversL_cent(n2_cent - 60, False))
ElseIf n2_cent >=82 And n2_cent <= 99
x_cent = "quatre-vingt-" + Trim(NversL_cent(n2_cent - 80, False))
EndIf
EndSelect
n1_cent = n1_cent - n2_cent
;Pour éviter 'cent zéro'
If Len(t_cent) = 0 Or Trim(x_cent) <> "zéro"
t_cent = t_cent + " " + x_cent
EndIf
ProcedureReturn t_cent
EndProcedure
Procedure.s NversL_chiffre(n_chiffre.l)
Protected n1_chiffre.l, t_chiffre.s
n1_chiffre = n_chiffre
Select n1_chiffre
Case 0
t_chiffre = "zéro"
Case 1
t_chiffre = "un"
Case 2
t_chiffre = "deux"
Case 3
t_chiffre = "trois"
Case 4
t_chiffre = "quatre"
Case 5
t_chiffre = "cinq"
Case 6
t_chiffre = "six"
Case 7
t_chiffre = "sept"
Case 8
t_chiffre = "huit"
Case 9
t_chiffre = "neuf"
EndSelect
ProcedureReturn t_chiffre
EndProcedure
Debug NversL(190.25)
190.25 => "Cent quatre-vingt-dixs et vingt-cinqs"

Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Participez à son extension: ajouter vos programmes et partagez vos codes !
Là y a vraiment un petit problème, ça déconne de 52 à 59:
Code : Tout sélectionner
Debug NversL(100.52)
Résultat: Cents et cinquante et uns
J'ai trouvé une autre source
Code : Tout sélectionner
Public Function ConvertNbLettres(Nb, Devise As String) As String
Dim varnum, varnumD, varnumU, resultat, varlet
Static Chiffre(1 To 19)
Chiffre(1) = "un"
Chiffre(2) = "deux"
Chiffre(3) = "trois"
Chiffre(4) = "quatre"
Chiffre(5) = "cinq"
Chiffre(6) = "six"
Chiffre(7) = "sept"
Chiffre(8) = "huit"
Chiffre(9) = "neuf"
Chiffre(10) = "dix"
Chiffre(11) = "onze"
Chiffre(12) = "douze"
Chiffre(13) = "treize"
Chiffre(14) = "quatorze"
Chiffre(15) = "quinze"
Chiffre(16) = "seize"
Chiffre(17) = "dix-sept"
Chiffre(18) = "dix-huit"
Chiffre(19) = "dix-neuf"
Static dizaine(1 To 8)
dizaine(1) = "dix"
dizaine(2) = "vingt"
dizaine(3) = "trente"
dizaine(4) = "quarante"
dizaine(5) = "cinquante"
dizaine(6) = "soixante"
dizaine(8) = "quatre-vingt"
'traitement du cas 0
If Nb >= 1 Then
resultat = ""
Else
resultat = "zéro"
Goto fintraitementfrancs
End If
'traitement des millions
varnum = Int(Nb / 1000000)
If varnum > 0 Then
Gosub centaine_dizaine
resultat = varlet + " million"
If varlet <> "un" Then: resultat = resultat + "s"
End If
'traitement des milliers
varnum = Int(Nb) Mod 1000000
varnum = Int(varnum / 1000)
If varnum > 0 Then
Gosub centaine_dizaine
If varlet <> "un" Then: resultat = resultat + " " + varlet
resultat = resultat + " mille"
End If
'traitement des centaines et dizaines
varnum = Int(Nb) Mod 1000
If varnum > 0 Then
Gosub centaine_dizaine
resultat = resultat + " " + varlet
End If
resultat = LTrim(resultat)
varlet = Right$(resultat, 4)
'traitement du "s" final pour vingt et cent et du "de" pour million
Select Case varlet
Case "cent", "ingt"
resultat = resultat + "s"
Case "lion", "ions"
resultat = resultat + " de"
End Select
fintraitementfrancs:
resultat = resultat + " " + Devise
If Nb > 2 Then: resultat = resultat + "s"
'traitement des centimes
varnum = Int((Nb - Int(Nb)) * 100 + 0.5)
If varnum > 0 Then
Gosub centaine_dizaine
resultat = resultat + " et " + varlet + " centime"
If varnum > 1 Then: resultat = resultat + "s"
End If
'conversion 1ère lettre en majuscule
resultat = UCase(Left(resultat, 1)) + Right(resultat, Len(resultat) - 1)
'renvoi du resultat de la fonction et fin de la fonction
ConvertNbLettres = resultat
Exit Function
'sous programme
centaine_dizaine:
varlet = ""
'traitement des centaines
If varnum >= 100 Then
varlet = Chiffre(Int(varnum / 100))
varnum = varnum Mod 100
If varlet = "un" Then
varlet = "cent "
Else
varlet = varlet + " cent "
End If
End If
'traitement des dizaines
If varnum <= 19 Then
If varnum > 0 Then: varlet = varlet + Chiffre(varnum)
Else
varnumD = Int(varnum / 10)
varnumU = varnum Mod 10
Select Case varnumD
Case Is <= 5
varlet = varlet + dizaine(varnumD)
Case 6, 7
varlet = varlet + dizaine(6)
Case 8, 9
varlet = varlet + dizaine(8)
End Select
If varnumU = 1 And varnumD < 8 Then
varlet = varlet + " et "
Else
If varnumU <> 0 Or varnumD = 7 Or varnumD = 9 Then: varlet = varlet + " "
End If
If varnumD = 7 Or varnumD = 9 Then: varnumU = varnumU + 10
If varnumU <> 0 Then: varlet = varlet + Chiffre(varnumU)
End If
varlet = RTrim(varlet)
Return
End Function
-
- Messages : 1500
- Inscription : jeu. 25/mars/2004 11:23
- Localisation : Sophia Antipolis (Nice)
- Contact :
Amuse toi à la traduire celle là...
Tu verra c'est pas très compliqué...
Mais sinon reprend l'autre ou faisant une toi même...

Tu verra c'est pas très compliqué...
Mais sinon reprend l'autre ou faisant une toi même...

Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Participez à son extension: ajouter vos programmes et partagez vos codes !
-
- Messages : 1500
- Inscription : jeu. 25/mars/2004 11:23
- Localisation : Sophia Antipolis (Nice)
- Contact :
VB c'est comme que PB pour la syntaxe... (à quelques modifs près...) :
PB :
If ... : ... : EndIf
Select ...
While : ... : Wend
VB :
If ... Then ... : End If
Select Case ....
While : ... : End While
Par contre pour retourner une valeur d'une fonction, il faut faire :
++
PB :
If ... : ... : EndIf
Select ...
While : ... : Wend
VB :
If ... Then ... : End If
Select Case ....
While : ... : End While
Par contre pour retourner une valeur d'une fonction, il faut faire :
Code : Tout sélectionner
Public Function ConvertNbLettres(Nb, Devise As String) As String
ConvertNbLettres = "Valeur de retour"
End Function
Webmestre de Basic-univers
Participez à son extension: ajouter vos programmes et partagez vos codes !
Participez à son extension: ajouter vos programmes et partagez vos codes !