-
Notifications
You must be signed in to change notification settings - Fork 767
Expand file tree
/
Copy pathNumberToWords.cs
More file actions
80 lines (70 loc) · 1.75 KB
/
NumberToWords.cs
File metadata and controls
80 lines (70 loc) · 1.75 KB
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
#nullable enable
namespace UICatalog;
public static class NumberToWords
{
private static readonly string [] _tens =
[
"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"
];
private static readonly string [] _units =
[
"Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Ten",
"Eleven",
"Twelve",
"Thirteen",
"Fourteen",
"Fifteen",
"Sixteen",
"Seventeen",
"Eighteen",
"Nineteen"
];
public static string Convert (long i)
{
if (i < 20)
{
return _units [i];
}
if (i < 100)
{
return _tens [i / 10] + (i % 10 > 0 ? " " + Convert (i % 10) : "");
}
if (i < 1000)
{
return _units [i / 100]
+ " Hundred"
+ (i % 100 > 0 ? " And " + Convert (i % 100) : "");
}
if (i < 100000)
{
return Convert (i / 1000)
+ " Thousand "
+ (i % 1000 > 0 ? " " + Convert (i % 1000) : "");
}
if (i < 10000000)
{
return Convert (i / 100000)
+ " Lakh "
+ (i % 100000 > 0 ? " " + Convert (i % 100000) : "");
}
if (i < 1000000000)
{
return Convert (i / 10000000)
+ " Crore "
+ (i % 10000000 > 0 ? " " + Convert (i % 10000000) : "");
}
return Convert (i / 1000000000)
+ " Arab "
+ (i % 1000000000 > 0 ? " " + Convert (i % 1000000000) : "");
}
}