public static string NumbersToWords(int inputNumber)
{
int inputNo = inputNumber;
if (inputNo == 0)
return "Zero";
int[] numbers = new int[4];
int first = 0;
int u, h, t;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (inputNo < 0)
{
sb.Append("Minus ");
inputNo = -inputNo;
}
string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ",
"Five " ,"Six ", "Seven ", "Eight ", "Nine "};
string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
"Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};
string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
"Seventy ","Eighty ", "Ninety "};
string[] words3 = { "Thousand ", "Lakh ", "Crore " };
numbers[0] = inputNo % 1000; // units
numbers[1] = inputNo / 1000;
numbers[2] = inputNo / 100000;
numbers[1] = numbers[1] - 100 * numbers[2]; // thousands
numbers[3] = inputNo / 10000000; // crores
numbers[2] = numbers[2] - 100 * numbers[3]; // lakhs
for (int i = 3; i > 0; i--)
{
if (numbers[i] != 0)
{
first = i;
break;
}
}
for (int i = first; i >= 0; i--)
{
if (numbers[i] == 0) continue;
u = numbers[i] % 10; // ones
t = numbers[i] / 10;
h = numbers[i] / 100; // hundreds
t = t - 10 * h; // tens
if (h > 0) sb.Append(words0[h] + "Hundred ");
if (u > 0 || t > 0)
{
if (h > 0 || i == 0) sb.Append("and ");
if (t == 0)
sb.Append(words0[u]);
else if (t == 1)
sb.Append(words1[u]);
else
sb.Append(words2[t - 2] + words0[u]);
}
if (i != 0) sb.Append(words3[i - 1]);
}
return sb.ToString().TrimEnd();
}

Programming is fun and interesting. As you all know, sometime we programmers stucks in the middle way of coding without getting a solution. Blogs like this will help us to find a path to solve our problems. The contents of this blog are the solutions that I found by myself and from other sources. Sharing such solutions is also interesting. Thank you!
Sunday, June 28, 2015
C# Function to Convert Number to Words
Thursday, May 28, 2015
Cursor Example in Sql Server 2008
Declare @name nvarchar(max)
Declare cur cursor for
select username from userdet
open cur
fetch next from cur into @name
while @@FETCH_STATUS=0
begin
print @name
fetch next from cur into @name
end
CLOSE CUR;
DEALLOCATE CUR;
Sunday, May 24, 2015
Asp.net C# code for download file
protected void DownloadFile(string Path, string FileName)
{
try
{
string strURL = Path;
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.AddHeader("Content-Disposition", "attachment;filename="+FileName);
byte[] data = req.DownloadData(Server.MapPath(strURL));
response.BinaryWrite(data);
response.End();
}
catch (Exception ex)
{
}
}
Friday, May 15, 2015
Check all Check boxes in a check box list ASP.NET + Jquery
Design
<asp:CheckBox ID="checkAllImport" runat="server" AutoPostBack="false" Text="Select All" />
<asp:CheckBoxList ID="chkOptions" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"></asp:CheckBoxList>
Script
<script type="text/javascript">
$(document).ready(function() {
$("#<%=checkAllImport.ClientID %>").change(function() {
$("input[id *='chkOptions']").prop("checked", this.checked);
})
});
</script>
Subscribe to:
Posts (Atom)