Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all of u,
i have a text box which shows numeric value.
i want to show that numeric value to words in another text box.
................how can it will be done......reply as soon as possible


with regards,
amit mehan
Posted

this maybe can help you Convert Cardinal Numbers (integers) into words see function GetNumber2(form)
 
Share this answer
 
hi u can try this:


XML
<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:

C#
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!";
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900