Bonjour,, j'ai besoin de votre aide
j'ai un montant que je veux le transformer en chiffre, vous avez une fonction qui fait ca ?
j'ai cherché sur le net mais je n'ai rien trouvé ?








Bonjour,, j'ai besoin de votre aide
j'ai un montant que je veux le transformer en chiffre, vous avez une fonction qui fait ca ?
j'ai cherché sur le net mais je n'ai rien trouvé ?
Tu peux utiliser la très bonne librairie HumanizerC'est open-source et dispo en Nuget: Humanizer
Less Is More
Pensez à utiliser les boutons
,
et les balises code
Desole pour l'absence d'accents, clavier US oblige
Celui qui pense qu'un professionnel coute cher n'a aucune idee de ce que peut lui couter un incompetent.
salut,
j'ai trouvé ceci sur le forum peut être que cela peut aider:
http://www.developpez.net/forums/d59...nombre-lettre/
tu veux dire quelque chose genre:
1345 devient "Mille trois cent quarante cinq" ?
C'est ça que tu aimerais avoir ?
voir :
http://www.developpez.net/forums/d59...nombre-lettre/
voir en cherchant un peu
http://projets.developpez.com/projec...toutes_lettres








et si le chiffre est avec une virgule ?
si il y a une virgule,
tu splittes et tu as deux fois un nombre à convertir... faut juste ajouter la virgule entre les deux chaines générées![]()








rebonjour, j'ai revu toutes les fonction en haut mais a chaque fois je plante, j'ai trouvé une fonction bien travaillé mais qui traduit en arabe et en anglais
du moment que j'aurais besoin de l'arabe aussi donc je l'ai utilisée et en meme temps j'ai remoduler la fonction de tel sorte a transformer les chiffres en francais :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541 using System; using System.Collections.Generic; using System.Linq; using System.Text; public class ToWord { /// Group Levels: 987,654,321.234 /// 234 : Group Level -1 /// 321 : Group Level 0 /// 654 : Group Level 1 /// 987 : Group Level 2 #region Varaibles & Properties /// <summary> /// integer part /// </summary> private long _intergerValue; /// <summary> /// Decimal Part /// </summary> private int _decimalValue; /// <summary> /// Number to be converted /// </summary> public Decimal Number { get; set; } /// <summary> /// Currency to use /// </summary> public CurrencyInfo Currency { get; set; } /// <summary> /// Frensh text to be placed before the generated text /// </summary> public String FrenshPrefixText { get; set; } /// <summary> /// Frensh text to be placed after the generated text /// </summary> public String FrenshSuffixText { get; set; } /// <summary> /// Arabic text to be placed before the generated text /// </summary> public String ArabicPrefixText { get; set; } /// <summary> /// Arabic text to be placed after the generated text /// </summary> public String ArabicSuffixText { get; set; } #endregion #region General /// <summary> /// Constructor: short version /// </summary> /// <param name="number">Number to be converted</param> /// <param name="currency">Currency to use</param> public ToWord(Decimal number, CurrencyInfo currency) { InitializeClass(number, currency, String.Empty, "only.", "", ""); } /// <summary> /// Constructor: Full Version /// </summary> /// <param name="number">Number to be converted</param> /// <param name="currency">Currency to use</param> /// <param name="FrenshPrefixText">Frensh text to be placed before the generated text</param> /// <param name="FrenshSuffixText">Frensh text to be placed after the generated text</param> /// <param name="arabicPrefixText">Arabic text to be placed before the generated text</param> /// <param name="arabicSuffixText">Arabic text to be placed after the generated text</param> public ToWord(Decimal number, CurrencyInfo currency, String FrenshPrefixText, String FrenshSuffixText, String arabicPrefixText, String arabicSuffixText) { InitializeClass(number, currency, FrenshPrefixText, FrenshSuffixText, arabicPrefixText, arabicSuffixText); } /// <summary> /// Initialize Class Varaibles /// </summary> /// <param name="number">Number to be converted</param> /// <param name="currency">Currency to use</param> /// <param name="FrenshPrefixText">Frensh text to be placed before the generated text</param> /// <param name="FrenshSuffixText">Frensh text to be placed after the generated text</param> /// <param name="arabicPrefixText">Arabic text to be placed before the generated text</param> /// <param name="arabicSuffixText">Arabic text to be placed after the generated text</param> private void InitializeClass(Decimal number, CurrencyInfo currency, String FrenshPrefixText, String FrenshSuffixText, String arabicPrefixText, String arabicSuffixText) { Number = number; Currency = currency; FrenshPrefixText = FrenshPrefixText; FrenshSuffixText = FrenshSuffixText; ArabicPrefixText = arabicPrefixText; ArabicSuffixText = arabicSuffixText; ExtractIntegerAndDecimalParts(); } /// <summary> /// Get Proper Decimal Value /// </summary> /// <param name="decimalPart">Decimal Part as a String</param> /// <returns></returns> private string GetDecimalValue(string decimalPart) { string result = String.Empty; if (Currency.PartPrecision != decimalPart.Length) { int decimalPartLength = decimalPart.Length; for (int i = 0; i < Currency.PartPrecision - decimalPartLength; i++) { decimalPart += "0"; //Fix for 1 number after decimal ( 10.5 , 1442.2 , 375.4 ) } result = String.Format("{0}.{1}", decimalPart.Substring(0, Currency.PartPrecision), decimalPart.Substring(Currency.PartPrecision, decimalPart.Length - Currency.PartPrecision)); result = (Math.Round(Convert.ToDecimal(result))).ToString(); } else result = decimalPart; for (int i = 0; i < Currency.PartPrecision - result.Length; i++) { result += "0"; } return result; } /// <summary> /// Eextract Interger and Decimal parts /// </summary> private void ExtractIntegerAndDecimalParts() { String[] splits = Number.ToString().Split('.'); _intergerValue = Convert.ToInt32(splits[0]); if (splits.Length > 1) _decimalValue = Convert.ToInt32(GetDecimalValue(splits[1])); } #endregion #region Frensh Number To Word #region Varaibles private static string[] FrenshOnes = new string[] { "Zéro", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neuf", "Dix", "Onze", "Douze", "Treize", "Quatorze", "Quinze", "Seize", "Dix-sept", "Dix-huit", "Dix-neuf" }; private static string[] FrenshTens = new string[] { "Vingt", "Trente", "Quarante", "Cinquante", "Soixante", "Soixante-dix", "Quatre-vingts", "Quatre-vingt-dix" }; private static string[] FrenshGroup = new string[] { "Cent", "Mille", "Million", "Milliard", "Trillion", "Quadrillion", "Quintillion", "Sextillian", "Septillion", "Octillion", "Nonillion", "Decillion", "Undecillion", "Duodecillion", "Tredecillion", "Quattuordecillion", "Quindecillion", "Sexdecillion", "Septendecillion", "Octodecillion", "Novemdecillion", "Vigintillion", "Unvigintillion", "Duovigintillion", "10^72", "10^75", "10^78", "10^81", "10^84", "10^87", "Vigintinonillion", "10^93", "10^96", "Duotrigintillion", "Trestrigintillion" }; #endregion /// <summary> /// Process a group of 3 digits /// </summary> /// <param name="groupNumber">The group number to process</param> /// <returns></returns> private string ProcessGroup(int groupNumber) { int tens = groupNumber % 100; int hundreds = groupNumber / 100; string retVal = String.Empty; if (hundreds > 0) { retVal = String.Format("{0} {1}", FrenshOnes[hundreds], FrenshGroup[0]); } if (tens > 0) { if (tens < 20) { retVal += ((retVal != String.Empty) ? " " : String.Empty) + FrenshOnes[tens]; } else { int ones = tens % 10; tens = (tens / 10) - 2; // 20's offset retVal += ((retVal != String.Empty) ? " " : String.Empty) + FrenshTens[tens]; if (ones > 0) { retVal += ((retVal != String.Empty) ? " " : String.Empty) + FrenshOnes[ones]; } } } return retVal; } /// <summary> /// Convert stored number to words using selected currency /// </summary> /// <returns></returns> public string ConvertToFrensh() { Decimal tempNumber = Number; if (tempNumber == 0) return "Zero"; string decimalString = ProcessGroup(_decimalValue); string retVal = String.Empty; int group = 0; if (tempNumber < 1) { retVal = FrenshOnes[0]; } else { while (tempNumber >= 1) { int numberToProcess = (int)(tempNumber % 1000); tempNumber = tempNumber / 1000; string groupDescription = ProcessGroup(numberToProcess); if (groupDescription != String.Empty) { if (group > 0) { retVal = String.Format("{0} {1}", FrenshGroup[group], retVal); } retVal = String.Format("{0} {1}", groupDescription, retVal); } group++; } } String formattedNumber = String.Empty; formattedNumber += (FrenshPrefixText != String.Empty) ? String.Format("{0} ", FrenshPrefixText) : String.Empty; formattedNumber += (retVal != String.Empty) ? retVal : String.Empty; formattedNumber += (retVal != String.Empty) ? (_intergerValue == 1 ? Currency.FrenshCurrencyName : Currency.FrenshPluralCurrencyName) : String.Empty; formattedNumber += (decimalString != String.Empty) ? " et " : String.Empty; formattedNumber += (decimalString != String.Empty) ? decimalString : String.Empty; formattedNumber += (decimalString != String.Empty) ? " " + (_decimalValue == 1 ? Currency.FrenshCurrencyPartName : Currency.FrenshPluralCurrencyPartName) : String.Empty; formattedNumber += (FrenshSuffixText != String.Empty) ? String.Format(" {0}", FrenshSuffixText) : String.Empty; return formattedNumber; } #endregion #region Arabic Number To Word #region Varaibles private static string[] arabicOnes = new string[] { String.Empty, "واحد", "اثنان", "ثلاثة", "أربعة", "خمسة", "ستة", "سبعة", "ثمانية", "تسعة", "عشرة", "أحد عشر", "اثنا عشر", "ثلاثة عشر", "أربعة عشر", "خمسة عشر", "ستة عشر", "سبعة عشر", "ثمانية عشر", "تسعة عشر" }; private static string[] arabicFeminineOnes = new string[] { String.Empty, "إحدى", "اثنتان", "ثلاث", "أربع", "خمس", "ست", "سبع", "ثمان", "تسع", "عشر", "إحدى عشرة", "اثنتا عشرة", "ثلاث عشرة", "أربع عشرة", "خمس عشرة", "ست عشرة", "سبع عشرة", "ثماني عشرة", "تسع عشرة" }; private static string[] arabicTens = new string[] { "عشرون", "ثلاثون", "أربعون", "خمسون", "ستون", "سبعون", "ثمانون", "تسعون" }; private static string[] arabicHundreds = new string[] { "", "مائة", "مئتان", "ثلاثمائة", "أربعمائة", "خمسمائة", "ستمائة", "سبعمائة", "ثمانمائة","تسعمائة" }; private static string[] arabicAppendedTwos = new string[] { "مئتا", "ألفا", "مليونا", "مليارا", "تريليونا", "كوادريليونا", "كوينتليونا", "سكستيليونا" }; private static string[] arabicTwos = new string[] { "مئتان", "ألفان", "مليونان", "ملياران", "تريليونان", "كوادريليونان", "كوينتليونان", "سكستيليونان" }; private static string[] arabicGroup = new string[] { "مائة", "ألف", "مليون", "مليار", "تريليون", "كوادريليون", "كوينتليون", "سكستيليون" }; private static string[] arabicAppendedGroup = new string[] { "", "ألفاً", "مليوناً", "ملياراً", "تريليوناً", "كوادريليوناً", "كوينتليوناً", "سكستيليوناً" }; private static string[] arabicPluralGroups = new string[] { "", "آلاف", "ملايين", "مليارات", "تريليونات", "كوادريليونات", "كوينتليونات", "سكستيليونات" }; #endregion /// <summary> /// Get Feminine Status of one digit /// </summary> /// <param name="digit">The Digit to check its Feminine status</param> /// <param name="groupLevel">Group Level</param> /// <returns></returns> private string GetDigitFeminineStatus(int digit, int groupLevel) { if (groupLevel == -1) { // if it is in the decimal part if (Currency.IsCurrencyPartNameFeminine) return arabicFeminineOnes[digit]; // use feminine field else return arabicOnes[digit]; } else if (groupLevel == 0) { if (Currency.IsCurrencyNameFeminine) return arabicFeminineOnes[digit];// use feminine field else return arabicOnes[digit]; } else return arabicOnes[digit]; } /// <summary> /// Process a group of 3 digits /// </summary> /// <param name="groupNumber">The group number to process</param> /// <returns></returns> private string ProcessArabicGroup(int groupNumber, int groupLevel, Decimal remainingNumber) { int tens = groupNumber % 100; int hundreds = groupNumber / 100; string retVal = String.Empty; if (hundreds > 0) { if (tens == 0 && hundreds == 2) // حالة المضاف retVal = String.Format("{0}", arabicAppendedTwos[0]); else // الحالة العادية retVal = String.Format("{0}", arabicHundreds[hundreds]); } if (tens > 0) { if (tens < 20) { // if we are processing under 20 numbers if (tens == 2 && hundreds == 0 && groupLevel > 0) { // This is special case for number 2 when it comes alone in the group if (_intergerValue == 2000 || _intergerValue == 2000000 || _intergerValue == 2000000000 || _intergerValue == 2000000000000 || _intergerValue == 2000000000000000 || _intergerValue == 2000000000000000000) retVal = String.Format("{0}", arabicAppendedTwos[groupLevel]); // في حالة الاضافة else retVal = String.Format("{0}", arabicTwos[groupLevel]);// في حالة الافراد } else { // General case if (retVal != String.Empty) retVal += " و "; if (tens == 1 && groupLevel > 0 && hundreds == 0) retVal += " "; else if ((tens == 1 || tens == 2) && (groupLevel == 0 || groupLevel == -1) && hundreds == 0 && remainingNumber == 0) retVal += String.Empty; // Special case for 1 and 2 numbers like: ليرة سورية و ليرتان سوريتان else retVal += GetDigitFeminineStatus(tens, groupLevel);// Get Feminine status for this digit } } else { int ones = tens % 10; tens = (tens / 10) - 2; // 20's offset if (ones > 0) { if (retVal != String.Empty) retVal += " و "; // Get Feminine status for this digit retVal += GetDigitFeminineStatus(ones, groupLevel); } if (retVal != String.Empty) retVal += " و "; // Get Tens text retVal += arabicTens[tens]; } } return retVal; } /// <summary> /// Convert stored number to words using selected currency /// </summary> /// <returns></returns> public string ConvertToArabic() { Decimal tempNumber = Number; if (tempNumber == 0) return "صفر"; // Get Text for the decimal part string decimalString = ProcessArabicGroup(_decimalValue, -1, 0); string retVal = String.Empty; Byte group = 0; while (tempNumber >= 1) { // seperate number into groups int numberToProcess = (int)(tempNumber % 1000); tempNumber = tempNumber / 1000; // convert group into its text string groupDescription = ProcessArabicGroup(numberToProcess, group, Math.Floor(tempNumber)); if (groupDescription != String.Empty) { // here we add the new converted group to the previous concatenated text if (group > 0) { if (retVal != String.Empty) retVal = String.Format("{0} {1}", "و", retVal); if (numberToProcess != 2) { if (numberToProcess % 100 != 1) { if (numberToProcess >= 3 && numberToProcess <= 10) // for numbers between 3 and 9 we use plural name retVal = String.Format("{0} {1}", arabicPluralGroups[group], retVal); else { if (retVal != String.Empty) // use appending case retVal = String.Format("{0} {1}", arabicAppendedGroup[group], retVal); else retVal = String.Format("{0} {1}", arabicGroup[group], retVal); // use normal case } } else { retVal = String.Format("{0} {1}", arabicGroup[group], retVal); // use normal case } } } retVal = String.Format("{0} {1}", groupDescription, retVal); } group++; } String formattedNumber = String.Empty; formattedNumber += (ArabicPrefixText != String.Empty) ? String.Format("{0} ", ArabicPrefixText) : String.Empty; formattedNumber += (retVal != String.Empty) ? retVal : String.Empty; if (_intergerValue != 0) { // here we add currency name depending on _intergerValue : 1 ,2 , 3--->10 , 11--->99 int remaining100 = (int)(_intergerValue % 100); if (remaining100 == 0) formattedNumber += Currency.Arabic1CurrencyName; else if (remaining100 == 1) formattedNumber += Currency.Arabic1CurrencyName; else if (remaining100 == 2) { if (_intergerValue == 2) formattedNumber += Currency.Arabic2CurrencyName; else formattedNumber += Currency.Arabic1CurrencyName; } else if (remaining100 >= 3 && remaining100 <= 10) formattedNumber += Currency.Arabic310CurrencyName; else if (remaining100 >= 11 && remaining100 <= 99) formattedNumber += Currency.Arabic1199CurrencyName; } formattedNumber += (_decimalValue != 0) ? " و " : String.Empty; formattedNumber += (_decimalValue != 0) ? decimalString : String.Empty; if (_decimalValue != 0) { // here we add currency part name depending on _intergerValue : 1 ,2 , 3--->10 , 11--->99 formattedNumber += " "; int remaining100 = (int)(_decimalValue % 100); if (remaining100 == 0) formattedNumber += Currency.Arabic1CurrencyPartName; else if (remaining100 == 1) formattedNumber += Currency.Arabic1CurrencyPartName; else if (remaining100 == 2) formattedNumber += Currency.Arabic2CurrencyPartName; else if (remaining100 >= 3 && remaining100 <= 10) formattedNumber += Currency.Arabic310CurrencyPartName; else if (remaining100 >= 11 && remaining100 <= 99) formattedNumber += Currency.Arabic1199CurrencyPartName; } formattedNumber += (ArabicSuffixText != String.Empty) ? String.Format(" {0}", ArabicSuffixText) : String.Empty; return formattedNumber; } #endregion }mais le probleme c'est qu'il y a des probleme par exemple :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279 using System; using System.Collections.Generic; using System.Linq; using System.Text; public class CurrencyInfo { public enum Currencies { Syria = 0, UAE, SaudiArabia, Tunisia, Gold, Maroc, France }; #region Constructors public CurrencyInfo(Currencies currency) { switch (currency) { case Currencies.Syria: CurrencyID = 0; CurrencyCode = "SYP"; IsCurrencyNameFeminine = true; FrenshCurrencyName = "Syrian Pound"; FrenshPluralCurrencyName = "Syrian Pounds"; FrenshCurrencyPartName = "Piaster"; FrenshPluralCurrencyPartName = "Piasteres"; Arabic1CurrencyName = "ليرة سورية"; Arabic2CurrencyName = "ليرتان سوريتان"; Arabic310CurrencyName = "ليرات سورية"; Arabic1199CurrencyName = "ليرة سورية"; Arabic1CurrencyPartName = "قرش"; Arabic2CurrencyPartName = "قرشان"; Arabic310CurrencyPartName = "قروش"; Arabic1199CurrencyPartName = "قرشاً"; PartPrecision = 2; IsCurrencyPartNameFeminine = false; break; case Currencies.UAE: CurrencyID = 1; CurrencyCode = "AED"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "UAE Dirham"; FrenshPluralCurrencyName = "UAE Dirhams"; FrenshCurrencyPartName = "Fils"; FrenshPluralCurrencyPartName = "Fils"; Arabic1CurrencyName = "درهم إماراتي"; Arabic2CurrencyName = "درهمان إماراتيان"; Arabic310CurrencyName = "دراهم إماراتية"; Arabic1199CurrencyName = "درهماً إماراتياً"; Arabic1CurrencyPartName = "فلس"; Arabic2CurrencyPartName = "فلسان"; Arabic310CurrencyPartName = "فلوس"; Arabic1199CurrencyPartName = "فلساً"; PartPrecision = 2; IsCurrencyPartNameFeminine = false; break; case Currencies.SaudiArabia: CurrencyID = 2; CurrencyCode = "SAR"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "Saudi Riyal"; FrenshPluralCurrencyName = "Saudi Riyals"; FrenshCurrencyPartName = "Halala"; FrenshPluralCurrencyPartName = "Halalas"; Arabic1CurrencyName = "ريال سعودي"; Arabic2CurrencyName = "ريالان سعوديان"; Arabic310CurrencyName = "ريالات سعودية"; Arabic1199CurrencyName = "ريالاً سعودياً"; Arabic1CurrencyPartName = "هللة"; Arabic2CurrencyPartName = "هللتان"; Arabic310CurrencyPartName = "هللات"; Arabic1199CurrencyPartName = "هللة"; PartPrecision = 2; IsCurrencyPartNameFeminine = true; break; case Currencies.Tunisia: CurrencyID = 3; CurrencyCode = "TND"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "Tunisian Dinar"; FrenshPluralCurrencyName = "Tunisian Dinars"; FrenshCurrencyPartName = "milim"; FrenshPluralCurrencyPartName = "millimes"; Arabic1CurrencyName = "دينار تونسي"; Arabic2CurrencyName = "ديناران تونسيان"; Arabic310CurrencyName = "دنانير تونسية"; Arabic1199CurrencyName = "ديناراً تونسياً"; Arabic1CurrencyPartName = "مليم"; Arabic2CurrencyPartName = "مليمان"; Arabic310CurrencyPartName = "ملاليم"; Arabic1199CurrencyPartName = "مليماً"; PartPrecision = 3; IsCurrencyPartNameFeminine = false; break; case Currencies.Gold: CurrencyID = 4; CurrencyCode = "XAU"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "Gram"; FrenshPluralCurrencyName = "Grams"; FrenshCurrencyPartName = "Milligram"; FrenshPluralCurrencyPartName = "Milligrams"; Arabic1CurrencyName = "جرام"; Arabic2CurrencyName = "جرامان"; Arabic310CurrencyName = "جرامات"; Arabic1199CurrencyName = "جراماً"; Arabic1CurrencyPartName = "ملجرام"; Arabic2CurrencyPartName = "ملجرامان"; Arabic310CurrencyPartName = "ملجرامات"; Arabic1199CurrencyPartName = "ملجراماً"; PartPrecision = 2; IsCurrencyPartNameFeminine = false; break; case Currencies.Maroc: CurrencyID = 5; CurrencyCode = "Mrc"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "Dirhame"; FrenshPluralCurrencyName = "Dirhames"; FrenshCurrencyPartName = "Centime"; FrenshPluralCurrencyPartName = "Centimes"; Arabic1CurrencyName = "درهم"; Arabic2CurrencyName = "درهمان"; Arabic310CurrencyName = "دراهم"; Arabic1199CurrencyName = "دراهما"; Arabic1CurrencyPartName = "سنتيم"; Arabic2CurrencyPartName = "سنتيمان"; Arabic310CurrencyPartName = "سنتيمات"; Arabic1199CurrencyPartName = "سنتيما"; PartPrecision = 2; IsCurrencyPartNameFeminine = false; break; case Currencies.France: CurrencyID = 6; CurrencyCode = "Fr"; IsCurrencyNameFeminine = false; FrenshCurrencyName = "Dirham"; FrenshPluralCurrencyName = "Dirhams"; FrenshCurrencyPartName = "Centime"; FrenshPluralCurrencyPartName = "Centimes"; Arabic1CurrencyName = "Dirham"; Arabic2CurrencyName = "Dirhams"; Arabic310CurrencyName = "Dirhams"; Arabic1199CurrencyName = "Dirhams"; Arabic1CurrencyPartName = "Centime"; Arabic2CurrencyPartName = "Centimes"; Arabic310CurrencyPartName = "Centimes"; Arabic1199CurrencyPartName = "Centime"; PartPrecision = 2; IsCurrencyPartNameFeminine = false; break; } } #endregion #region Properties /// <summary> /// Currency ID /// </summary> public int CurrencyID { get; set; } /// <summary> /// Standard Code /// Syrian Pound: SYP /// UAE Dirham: AED /// </summary> public string CurrencyCode { get; set; } /// <summary> /// Is the currency name feminine ( Mua'anath مؤنث) /// ليرة سورية : مؤنث = true /// درهم : مذكر = false /// </summary> public Boolean IsCurrencyNameFeminine { get; set; } /// <summary> /// Frensh Currency Name for single use /// Syrian Pound /// UAE Dirham /// </summary> public string FrenshCurrencyName { get; set; } /// <summary> /// Frensh Plural Currency Name for Numbers over 1 /// Syrian Pounds /// UAE Dirhams /// </summary> public string FrenshPluralCurrencyName { get; set; } /// <summary> /// Arabic Currency Name for 1 unit only /// ليرة سورية /// درهم إماراتي /// </summary> public string Arabic1CurrencyName { get; set; } /// <summary> /// Arabic Currency Name for 2 units only /// ليرتان سوريتان /// درهمان إماراتيان /// </summary> public string Arabic2CurrencyName { get; set; } /// <summary> /// Arabic Currency Name for 3 to 10 units /// خمس ليرات سورية /// خمسة دراهم إماراتية /// </summary> public string Arabic310CurrencyName { get; set; } /// <summary> /// Arabic Currency Name for 11 to 99 units /// خمس و سبعون ليرةً سوريةً /// خمسة و سبعون درهماً إماراتياً /// </summary> public string Arabic1199CurrencyName { get; set; } /// <summary> /// Decimal Part Precision /// for Syrian Pounds: 2 ( 1 SP = 100 parts) /// for Tunisian Dinars: 3 ( 1 TND = 1000 parts) /// </summary> public Byte PartPrecision { get; set; } /// <summary> /// Is the currency part name feminine ( Mua'anath مؤنث) /// هللة : مؤنث = true /// قرش : مذكر = false /// </summary> public Boolean IsCurrencyPartNameFeminine { get; set; } /// <summary> /// Frensh Currency Part Name for single use /// Piaster /// Fils /// </summary> public string FrenshCurrencyPartName { get; set; } /// <summary> /// Frensh Currency Part Name for Plural /// Piasters /// Fils /// </summary> public string FrenshPluralCurrencyPartName { get; set; } /// <summary> /// Arabic Currency Part Name for 1 unit only /// قرش /// هللة /// </summary> public string Arabic1CurrencyPartName { get; set; } /// <summary> /// Arabic Currency Part Name for 2 unit only /// قرشان /// هللتان /// </summary> public string Arabic2CurrencyPartName { get; set; } /// <summary> /// Arabic Currency Part Name for 3 to 10 units /// قروش /// هللات /// </summary> public string Arabic310CurrencyPartName { get; set; } /// <summary> /// Arabic Currency Part Name for 11 to 99 units /// قرشاً /// هللةً /// </summary> public string Arabic1199CurrencyPartName { get; set; } #endregion }
123 : il l'a traduit en "un cent ..."
458795 DH ( Quatre Cent Cinquante Huit Mille Sept Cent Quatre-vingt-dix Cinq Dirhams )
une idée ?
Pour cette fonction :
il me dis qu'il y a un probleme de conversion sur la ligne : reste = chiffre / 1;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 // created on 25/03/2004 at 14:14 using System; //namespace toto; namespace toto.convertisseur { public class ConvertisseurChiffresLettres{ public string converti(float chiffre){ int centaine, dizaine, unite, reste, y; bool dix = false; string lettre = ""; //strcpy(lettre, ""); reste = chiffre / 1; for(int i=1000000000; i>=1; i/=1000) { y = reste/i; if(y!=0) { centaine = y/100; dizaine = (y - centaine*100)/10; unite = y-(centaine*100)-(dizaine*10); switch(centaine) { case 0: break; case 1: lettre += "cent "; break; case 2: if((dizaine == 0)&&(unite == 0)) lettre +="deux cents "; else lettre +="deux cent "; break; case 3: if((dizaine == 0)&&(unite == 0)) lettre += "trois cents "; else lettre += "trois cent "; break; case 4: if((dizaine == 0)&&(unite == 0)) lettre+="quatre cents "; else lettre +="quatre cent "; break; case 5: if((dizaine == 0)&&(unite == 0)) lettre+="cinq cents "; else lettre+="cinq cent "; break; case 6: if((dizaine == 0)&&(unite == 0)) lettre+="six cents "; else lettre += "six cent "; break; case 7: if((dizaine == 0)&&(unite == 0)) lettre+="sept cents "; else lettre+="sept cent "; break; case 8: if((dizaine == 0)&&(unite == 0)) lettre+="huit cents "; else lettre+="huit cent "; break; case 9: if((dizaine == 0)&&(unite == 0)) lettre+="neuf cents "; else lettre+="neuf cent "; }// endSwitch(centaine) switch(dizaine) { case 0: break; case 1: dix = true; break; case 2: lettre+="vingt "; break; case 3: lettre+="trente "; break; case 4: lettre+="quarante "; break; case 5: lettre+="cinquante "; break; case 6: lettre+="soixante "; break; case 7: dix = true; lettre+="soixante "; break; case 8: lettre+="quatre-vingt "; break; case 9: dix = true; lettre+="quatre-vingt "; } // endSwitch(dizaine) switch(unite) { case 0: if(dix) lettre+="dix "; break; case 1: if(dix) lettre+="onze "; else lettre+="un "; break; case 2: if(dix) lettre+="douze "; else lettre+="deux "; break; case 3: if(dix) lettre+="treize "; else lettre+="trois "; break; case 4: if(dix) lettre+="quatorze "; else lettre+="quatre "; break; case 5: if(dix) lettre+="quinze "; else lettre+="cinq "; break; case 6: if(dix) lettre+="seize "; else lettre+="six "; break; case 7: if(dix) lettre+="dix-sept "; else lettre+="sept "; break; case 8: if(dix) lettre+="dix-huit "; else lettre+="huit "; break; case 9: if(dix) lettre+="dix-neuf "; else lettre+="neuf "; } // endSwitch(unite) switch (i) { case 1000000000: if(y>1) lettre+="milliards "; else lettre+="milliard "; break; case 1000000: if(y>1) lettre+="millions "; else lettre+="million "; break; case 1000: lettre+="mille "; } } // end if(y!=0) reste -= y*i; dix = false; } // end for if(lettre.Length ==0) lettre+="zero"; return lettre; } } }
J'ai pris ta fonction, je l'ai mis dans mon VS, et comme elle ne compilait pas, j'ai ajouté les Break nécessaires... qui auraient du y être sinon le compilo gueulait (passons..)
string res = converti(458795); ==> m'a donné le résultat que tu attendais (quatre-vingt quinze)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 public static string converti(float chiffre) { int centaine, dizaine, unite, reste, y; bool dix = false; string lettre = ""; //strcpy(lettre, ""); reste = (int)chiffre / 1; for (int i = 1000000000; i >= 1; i /= 1000) { y = reste / i; if (y != 0) { centaine = y / 100; dizaine = (y - centaine * 100) / 10; unite = y - (centaine * 100) - (dizaine * 10); switch (centaine) { case 0: break; case 1: lettre += "cent "; break; case 2: if ((dizaine == 0) && (unite == 0)) lettre += "deux cents "; else lettre += "deux cent "; break; case 3: if ((dizaine == 0) && (unite == 0)) lettre += "trois cents "; else lettre += "trois cent "; break; case 4: if ((dizaine == 0) && (unite == 0)) lettre += "quatre cents "; else lettre += "quatre cent "; break; case 5: if ((dizaine == 0) && (unite == 0)) lettre += "cinq cents "; else lettre += "cinq cent "; break; case 6: if ((dizaine == 0) && (unite == 0)) lettre += "six cents "; else lettre += "six cent "; break; case 7: if ((dizaine == 0) && (unite == 0)) lettre += "sept cents "; else lettre += "sept cent "; break; case 8: if ((dizaine == 0) && (unite == 0)) lettre += "huit cents "; else lettre += "huit cent "; break; case 9: if ((dizaine == 0) && (unite == 0)) lettre += "neuf cents "; else lettre += "neuf cent "; break; }// endSwitch(centaine) switch (dizaine) { case 0: break; case 1: dix = true; break; case 2: lettre += "vingt "; break; case 3: lettre += "trente "; break; case 4: lettre += "quarante "; break; case 5: lettre += "cinquante "; break; case 6: lettre += "soixante "; break; case 7: dix = true; lettre += "soixante "; break; case 8: lettre += "quatre-vingt "; break; case 9: dix = true; lettre += "quatre-vingt "; break; } // endSwitch(dizaine) switch (unite) { case 0: if (dix) lettre += "dix "; break; case 1: if (dix) lettre += "onze "; else lettre += "un "; break; case 2: if (dix) lettre += "douze "; else lettre += "deux "; break; case 3: if (dix) lettre += "treize "; else lettre += "trois "; break; case 4: if (dix) lettre += "quatorze "; else lettre += "quatre "; break; case 5: if (dix) lettre += "quinze "; else lettre += "cinq "; break; case 6: if (dix) lettre += "seize "; else lettre += "six "; break; case 7: if (dix) lettre += "dix-sept "; else lettre += "sept "; break; case 8: if (dix) lettre += "dix-huit "; else lettre += "huit "; break; case 9: if (dix) lettre += "dix-neuf "; else lettre += "neuf "; break; } // endSwitch(unite) switch (i) { case 1000000000: if (y > 1) lettre += "milliards "; else lettre += "milliard "; break; case 1000000: if (y > 1) lettre += "millions "; else lettre += "million "; break; case 1000: lettre += "mille "; break; } } // end if(y!=0) reste -= y * i; dix = false; } // end for if (lettre.Length == 0) lettre += "zero"; return lettre; }








voila ce que j'ai fait quand je veux traduire aussi le chiffre apres la virgule :
c'est OK ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 public class Number2Lettres { private string convertir(int chiffre) { int centaine, dizaine, unite, reste, y; bool dix = false; string lettre = ""; //strcpy(lettre, ""); reste = (int)chiffre / 1; for (int i = 1000000000; i >= 1; i /= 1000) { y = reste / i; if (y != 0) { centaine = y / 100; dizaine = (y - centaine * 100) / 10; unite = y - (centaine * 100) - (dizaine * 10); switch (centaine) { case 0: break; case 1: lettre += "cent "; break; case 2: if ((dizaine == 0) && (unite == 0)) lettre += "deux cents "; else lettre += "deux cent "; break; case 3: if ((dizaine == 0) && (unite == 0)) lettre += "trois cents "; else lettre += "trois cent "; break; case 4: if ((dizaine == 0) && (unite == 0)) lettre += "quatre cents "; else lettre += "quatre cent "; break; case 5: if ((dizaine == 0) && (unite == 0)) lettre += "cinq cents "; else lettre += "cinq cent "; break; case 6: if ((dizaine == 0) && (unite == 0)) lettre += "six cents "; else lettre += "six cent "; break; case 7: if ((dizaine == 0) && (unite == 0)) lettre += "sept cents "; else lettre += "sept cent "; break; case 8: if ((dizaine == 0) && (unite == 0)) lettre += "huit cents "; else lettre += "huit cent "; break; case 9: if ((dizaine == 0) && (unite == 0)) lettre += "neuf cents "; else lettre += "neuf cent "; break; }// endSwitch(centaine) switch (dizaine) { case 0: break; case 1: dix = true; break; case 2: lettre += "vingt "; break; case 3: lettre += "trente "; break; case 4: lettre += "quarante "; break; case 5: lettre += "cinquante "; break; case 6: lettre += "soixante "; break; case 7: dix = true; lettre += "soixante "; break; case 8: lettre += "quatre-vingt "; break; case 9: dix = true; lettre += "quatre-vingt "; break; } // endSwitch(dizaine) switch (unite) { case 0: if (dix) lettre += "dix "; break; case 1: if (dix) lettre += "onze "; else lettre += "un "; break; case 2: if (dix) lettre += "douze "; else lettre += "deux "; break; case 3: if (dix) lettre += "treize "; else lettre += "trois "; break; case 4: if (dix) lettre += "quatorze "; else lettre += "quatre "; break; case 5: if (dix) lettre += "quinze "; else lettre += "cinq "; break; case 6: if (dix) lettre += "seize "; else lettre += "six "; break; case 7: if (dix) lettre += "dix-sept "; else lettre += "sept "; break; case 8: if (dix) lettre += "dix-huit "; else lettre += "huit "; break; case 9: if (dix) lettre += "dix-neuf "; else lettre += "neuf "; break; } // endSwitch(unite) switch (i) { case 1000000000: if (y > 1) lettre += "milliards "; else lettre += "milliard "; break; case 1000000: if (y > 1) lettre += "millions "; else lettre += "million "; break; case 1000: lettre += "mille "; break; } } // end if(y!=0) reste -= y * i; dix = false; } // end for if (lettre.Length == 0) lettre += "zero"; return lettre; } public string NumberConverted(double Number) { string integerLetter = "", decimalLetter ="", FormattedLetter = ""; int intergerValue =0, decimalValue=0; String[] splits = Number.ToString().Split('.'); intergerValue = Convert.ToInt32(splits[0]); if (splits.Length > 1) //get decimal value { string decimalPart = splits[1] ; int partPrecision = 2; string result = String.Empty; if (partPrecision != decimalPart.Length) { int decimalPartLength = decimalPart.Length; for (int i = 0; i < partPrecision - decimalPartLength; i++) { decimalPart += "0"; //Fix for 1 number after decimal ( 10.5 , 1442.2 , 375.4 ) } result = String.Format("{0}.{1}", decimalPart.Substring(0, partPrecision), decimalPart.Substring(partPrecision, decimalPart.Length - partPrecision)); result = (Math.Round(Convert.ToDecimal(result))).ToString(); } else result = decimalPart; for (int i = 0; i < partPrecision - result.Length; i++) { result += "0"; } decimalValue = Convert.ToInt32(result); } #region integerValuevalue if(intergerValue != 0) integerLetter = convertir(intergerValue); #endregion #region decimalvalue if(decimalValue != 0) decimalLetter = convertir(decimalValue); #endregion if ((decimalValue != 0 && intergerValue != 0)) FormattedLetter = integerLetter + " Dirhams et " + decimalLetter + " Centimes"; if ((decimalValue == 0 && intergerValue != 0)) FormattedLetter = integerLetter + " Dirhams"; if ((decimalValue == 0 && intergerValue == 0)) FormattedLetter = "Zéro Dirhams"; return FormattedLetter; } } }
Partager