-
Notifications
You must be signed in to change notification settings - Fork 0
/
RyNumber.cs
507 lines (493 loc) · 15.2 KB
/
RyNumber.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace RahimyGroup
{
public class RyNumber
{
/***** Persian Version *****/
private static string R1_FA(int iVal)
{
switch (iVal)
{
case 1:
return "یک ";
break;
case 2:
return "دو ";
break;
case 3:
return "سه ";
break;
case 4:
return "چهار ";
break;
case 5:
return "پنج ";
break;
case 6:
return "شش ";
break;
case 7:
return "هفت ";
break;
case 8:
return "هشت ";
break;
case 9:
return "نه ";
break;
default:
return "";
}
}
private static string R2_FA(int iVal)
{
int N1 = 0;
int N10 = 0;
if (iVal != 10)
{
N1 = iVal % 10;
N10 = iVal - N1;
}
switch (iVal)
{
case 10:
return "ده ";
break;
case 11:
return "یازده ";
break;
case 12:
return "دوازده ";
break;
case 13:
return "سیزده ";
break;
case 14:
return "چهارده ";
break;
case 15:
return "پانزده ";
break;
case 16:
return "شانزده ";
break;
case 17:
return "هفده ";
break;
case 18:
return "هجده ";
break;
case 19:
return "نوزده ";
break;
case 20:
return "بیست ";
break;
case 30:
return "سی ";
break;
case 40:
return "چهل ";
break;
case 50:
return "پنجاه ";
break;
case 60:
return "شصت ";
break;
case 70:
return "هفتاد ";
break;
case 80:
return "هشتاد ";
break;
case 90:
return "نود ";
break;
default:
return (R2_FA(N10) + " و " + R1_FA(N1));
}
}
private static string R3_FA(int iVal)
{
int N10 = 0;
int N100 = 0;
N10 = iVal % 100;
N100 = iVal - N10;
switch (iVal)
{
case 100:
return "یکصد ";
break;
case 200:
return "دویست ";
break;
case 300:
return "سیصد ";
break;
case 400:
return "چهارصد ";
break;
case 500:
return "پانصد ";
break;
case 600:
return "ششصد ";
break;
case 700:
return "هفتصد ";
break;
case 800:
return "هشتصد ";
break;
case 900:
return "نهصد ";
break;
default:
if (N10 >= 10)
return (R3_FA(N100) + " و " + R2_FA(N10));
else
return (R3_FA(N100) + " و " + R1_FA(N10));
}
}
public static string N2L_FA(Int64 iVal)
{
int[] P3D = new int[5];
string N2L = "";
int TN = 0;
int Temp;
int TL = 0;
string sTemp = "";
string Number = iVal.ToString();
int L = Number.Length;
int I = 0;
while (I < L)
{
I += 3;
Temp = 0;
sTemp = "000" + Number;
sTemp = sTemp.Substring(sTemp.Length - I, I);
Temp = int.Parse(sTemp.Substring(0, 3));
P3D[I / 3] = Temp;
}
I = 4;
while (I >= 0)
{
TN = P3D[I];
TL = TN.ToString().Length;
switch (TL)
{
case 1:
N2L += R1_FA(TN);
break;
case 2:
N2L += R2_FA(TN);
break;
case 3:
N2L += R3_FA(TN);
break;
}
if (TN != 0)
{
switch (I)
{
case 1:
N2L += "";
break;
case 2:
if (P3D[I - 1] != 0)
N2L += "هزار و ";
else
N2L += "هزار ";
break;
case 3:
if (P3D[I - 1] != 0)
N2L += "میلیون و ";
else
{
if (P3D[I - 2] != 0)
N2L += "میلیون و ";
else
N2L += "میلیون ";
}
break;
case 4:
if (P3D[I - 1] != 0)
N2L += "میلیارد و ";
else
{
if (P3D[I - 2] != 0)
N2L += "میلیارد و ";
else
N2L += "میلیارد ";
}
break;
case 5:
if (P3D[I - 1] != 0)
N2L += "تریلیون و ";
else
{
if (P3D[I - 2] != 0)
N2L += "تریلیون و ";
else
{
if (P3D[I - 3] != 0)
N2L += "تریلیون و ";
else
N2L += "تریلیون ";
}
}
break;
}
}
I--;
}
return N2L;
}
/***** English Version *****/
private static string R1_EN(int iVal)
{
switch (iVal)
{
case 1:
return "one ";
break;
case 2:
return "two ";
break;
case 3:
return "three ";
break;
case 4:
return "four ";
break;
case 5:
return "five ";
break;
case 6:
return "six ";
break;
case 7:
return "seven ";
break;
case 8:
return "eight ";
break;
case 9:
return "nine ";
break;
default:
return "";
break;
}
}
private static string R2_EN(int iVal)
{
int N1 = 0;
int N10 = 0;
if (iVal != 10)
{
N1 = iVal % 10;
N10 = iVal - N1;
}
switch (iVal)
{
case 10:
return "ten ";
break;
case 11:
return "eleven ";
break;
case 12:
return "twelve ";
break;
case 13:
return "thirteen ";
break;
case 14:
return "fourteen ";
break;
case 15:
return "fifteen ";
break;
case 16:
return "sixteen ";
break;
case 17:
return "seventeen ";
break;
case 18:
return "eighteen ";
break;
case 19:
return "nineteen ";
break;
case 20:
return "twenty";
break;
case 30:
return "thirty";
break;
case 40:
return "fourty";
break;
case 50:
return "fifty";
break;
case 60:
return "sixty";
break;
case 70:
return "seventy";
break;
case 80:
return "eighty";
break;
case 90:
return "ninty";
break;
default:
return (R2_EN(N10) + "-" + R1_EN(N1));
}
}
private static string R3_EN(int iVal)
{
int N10 = 0;
int N100 = 0;
N10 = iVal % 100;
N100 = iVal - N10;
switch (iVal)
{
case 100:
return "one hundred ";
break;
case 200:
return "two hundred ";
break;
case 300:
return "three hundred ";
break;
case 400:
return "four hundred ";
break;
case 500:
return "five hundred ";
break;
case 600:
return "six hundred ";
break;
case 700:
return "seven hundred ";
break;
case 800:
return "eight hundred ";
break;
case 900:
return "nine hundred ";
break;
default:
if (N10 >= 10)
return (R3_EN(N100) + "" + R2_EN(N10));
else
return (R3_EN(N100) + "" + R1_EN(N10));
}
}
public static string N2L_EN(Int64 iVal)
{
int[] P3D = new int[5];
string N2L = "";
int TN = 0;
int Temp;
int TL = 0;
string sTemp = "";
string Number = iVal.ToString();
int L = Number.Length;
int I = 0;
while (I < L)
{
I += 3;
Temp = 0;
sTemp = "000" + Number;
sTemp = sTemp.Substring(sTemp.Length - I, I);
Temp = int.Parse(sTemp.Substring(0, 3));
P3D[I / 3] = Temp;
}
I = 4;
while (I >= 0)
{
TN = P3D[I];
TL = TN.ToString().Length;
switch (TL)
{
case 1:
N2L += R1_EN(TN);
break;
case 2:
N2L += R2_EN(TN);
break;
case 3:
N2L += R3_EN(TN);
break;
}
if (TN != 0)
{
switch (I)
{
case 1:
N2L += "";
break;
case 2:
if (P3D[I - 1] != 0)
N2L += "thousand ";
else
N2L += "thousand ";
break;
case 3:
if (P3D[I - 1] != 0)
N2L += "million ";
else
{
if (P3D[I - 2] != 0)
N2L += "million ";
else
N2L += "million ";
}
break;
case 4:
if (P3D[I - 1] != 0)
N2L += "billion ";
else
{
if (P3D[I - 2] != 0)
N2L += "billion ";
else
N2L += "billion ";
}
break;
case 5:
if (P3D[I - 1] != 0)
N2L += "trillion ";
else
{
if (P3D[I - 2] != 0)
N2L += "trillion ";
else
{
if (P3D[I - 3] != 0)
N2L += "trillion ";
else
N2L += "trillion ";
}
}
break;
}
}
I--;
}
return N2L;
}
}
}