-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndianNumberSystem.cs
More file actions
188 lines (163 loc) · 6.16 KB
/
IndianNumberSystem.cs
File metadata and controls
188 lines (163 loc) · 6.16 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
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
/*
********************** CONVERT NUMBERS TO WORDS W.R.T. INDIAN CURRENCY VERBAL FORMS (Version 0)**********************
*************************************** Author- UJay(jadhav.utkarsh@gmail.com) Date-23 January 2014 *********************
*********************************************************************************************************************
*HOW TO ADD-
*
* Solution Explorer>Right Click>Add> Add Existing Item...>
*
*
*EXAMPLE-
*
* 1) Create object of IndianNumberSystem.
* IndianNumberSystem nu = new IndianNumberSystem();
*
* 2) Methods-
* I) for string without formatting [only one parameter int]
* string str=nu.convertNumToWord(69); output- Sixty-nine
*
* II) for string with prefix rupees[Two parameters int,string]
* string str=nu.convertNumToWord(169,"r"); output- rupees one hundred and sixty-nine
*
* III) for titled string i.e. each starting letter in uppercase[Two parameters int,string]
* string str=nu.convertNumToWord(1169,"t") output - One Thousand One Hundred And Sixty-nine
*
* IV) for slash dash symbol "/-" at the end use "s" in 2nd parameter[Two parameters int,string]
* string str=nu.convertNumToWord(1169,"st") output - One Thousand One Hundred And Sixty-nine/-
*
* V) for suffix "only" after word use "o" in second parameter[Two parameters int,string]
* string str=nu.convertNumToWord(1169,"ost") output - One Thousand One Hundred And Sixty-nine Only/-
*
* VI) using all i.e. "rost"
* string str=nu.convertNumToWord(1169,"rost") output - Rupees One Thousand One Hundred And Sixty-nine Only/-
*
*****************************************************************************************************************
*
*****************************************************************************************************************
*****************In case of bugs, and suggestions, shoot an email on jadhav.utkarsh@gmail.com********************
*
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
namespace IndianNumberSystem
{
class IndianNumberSystem
{
private uint crore= 10000000;
private uint lakh = 100000;
private uint thou = 1000;
private uint hun = 100;
//PUBLIC "convertNumToWord" Methods
public string convertNumToWord(uint number,string para)
{
String word = convertToName(number);
if (para.Contains("r"))
word = "rupees " + word;
if (para.Contains("o"))
word +=" only";
if (para.Contains("s"))
word +="/-";
if (para.Contains("t"))
{
string temp_word = make_it_titled(word);
word = temp_word;
}
return word;
}
//FOR NUMBERS WITHOUT ANY ADDITIONAL FORMATTING
public string convertNumToWord(uint num)
{
string temp_word=convertToName(num);
string word = make_it_titled(temp_word);
return word;
}
//PRIVATE METHODS
//CONVERT NUMBERS TO NAME
private string convertToName(uint number)
{
string word = "";
if (number == 0)
{
word = "zero";
return word;
}
if ((number / crore) > 0)
{
if ((number / crore)> 1)
word += convertToName(number / crore) + " crores ";
else
word += convertToName(number / crore) + " crore ";
number %= crore;
}
if ((number / lakh) > 0)
{
word += convertToName(number / lakh) + " lakh";
if ((number / lakh) > 1)
word += "s ";
number %= lakh;
}
if ((number / thou) > 0)
{
word += convertToName(number / thou) + " thousand ";
number %= thou;
}
if ((number / hun) > 0)
{
word += convertToName(number / hun) + " hundred ";
number %= hun;
}
if (number > 0)
{
if (number < 1000)
{
if (word != "")
word += "and ";
}
var unitPos = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
var tenPos = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
if (number < 20)
word += unitPos[number];
else
{
word += tenPos[number / 10];
if ((number % 10) > 0)
word +="-" + unitPos[number % 10];
}
}
return word;
}
//MAKE THE STRING TITLED i.e. MAKE EVERY FIRST ALPHABET IN UPPERCASE
private String make_it_titled(String word)
{
char[] words = new char[5000];
for (int i = 0; i < word.Length; i++)
{
if(i!=0)
{
if (word[i - 1] == ' ' & word[i]!='/')
words[i] = Convert.ToChar((int)word[i] - 32);
else
words[i] = word[i];
}
else
words[i] = Convert.ToChar((int)word[i] - 32);
}
string temp_word = " ";
for (int i = 0; i < words.Length; i++)
{
temp_word += words[i];
}
return temp_word;
}
//End of Class.
}
}