hi u can try this:
<div>
Enter Numbers (0-1000) :
<asp:TextBox ID="txtnumbers" runat="server"></asp:TextBox>
<asp:Button ID="btnConvert" Text="Convert" runat="server"
onclick="btnConvert_Click" /><br />
In Words :
<asp:Label ID="lblNumberWords" runat="server" Text=""></asp:Label>
</div>
code behind is:
protected void btnConvert_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
int no = int.Parse(txtnumbers.Text);
int length = txtnumbers.Text.Trim().Length;
for (int index = length; index > 0; index--)
{
if (index == 1)
{
sb.Append(convertToWord(no));
}
else
{
int dig = no / (Power(index));
no = no % (Power(index));
sb.Append(convertToWord(dig)+" ");
}
}
lblNumberWords.Text = sb.ToString();
}
private int Power(int index)
{
int res=1;
if (index == 1) ;
else
res = 10 * Power(index - 1);
return res;
}
private string convertToWord(int digit)
{
switch (digit)
{
case 1:
return "one";
case 2:
return "two";
case 3:
return "three";
case 4:
return "four";
case 5:
return "five";
case 6:
return "six";
case 7:
return "seven";
case 8:
return "eight";
case 9:
return "nine";
}
return "Enter Digits!";
}