HI WELCOME TO KANSIRIS

HOW TO CONVERT RUPEES,CURRENCY OR NUMBERS TO WORDS IN ASP.NET C#

Leave a Comment

Implementation: Let's create an asp.net web application to see it in action.
  • In the design page (.aspx) place two TextBox controls and a Button controls and design the web page as:
<fieldset style="width: 500PX;">
    <legend>Convert Rupees/Numbers to words in Asp.net</legend> 
    <table>
    <tr><td>Enter rupees in number: </td>
    <td><asp:TextBox ID="txtNumber" runat="server" MaxLength="9"></asp:TextBox><asp:Button ID="btnConvert"runat="server" Text="Convert To Words"
                onclick="btnConvert_Click"  /><asp:RequiredFieldValidator ID="rfvNumber"
                    runat="server" ErrorMessage="Please enter rupees/number"
            ControlToValidate="txtNumber" Display="Dynamic" ForeColor="#FF3300"
            SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:RangeValidator ID="rngNumber" runat="server" ControlToValidate="txtNumber"
            Display="Dynamic" ErrorMessage="Please enter rupees/number from 1 to 999999999"
            ForeColor="#FF3300" MaximumValue="999999999" MinimumValue="1"
            SetFocusOnError="True" Type="Integer"></asp:RangeValidator>
        </td>
    </tr>      
    <tr>
        <td>Converted Rupees in Words: </td>
        <td><asp:TextBox ID="txtWords" runat="server" Rows="3" ReadOnly="True"
                TextMode="MultiLine" Width="331px"></asp:TextBox></td>
    </tr>   
    </table>
      </fieldset>       

C#.Net Code to convert Rupees,Currency or Numbers to words in Asp.net
  •  In the Code behind file (.aspx.cs) write the code as:
protected void btnConvert_Click(object sender, EventArgs e)
    {
        Int64 NumVal = Convert.ToInt64(txtNumber.Text.Trim());      
        txtWords.Text = Rupees(NumVal);
    } 
    public string Rupees(Int64 rup)
    {
        string result="";
        Int64 res;
       if(( rup / 10000000) > 0)
    {
      res =  rup / 10000000;
      rup =  rup % 10000000;
      result = result + ' ' + RupeesToWords(res) + " Crore";
    }
    if(( rup / 100000) > 0)
    {
      res =  rup / 100000;
      rup =  rup % 100000;
      result = result + ' ' + RupeesToWords(res) + " Lack";
    }
    if(( rup / 1000) > 0)
    {
      res =  rup / 1000;
      rup =  rup % 1000;
      result = result + ' ' + RupeesToWords(res) + " Thousand";
    }
    if(( rup / 100) > 0)
    {
      res =  rup / 100;
      rup =  rup % 100;
      result = result + ' ' + RupeesToWords(res) + " Hundred";
    }
    if ((rup % 10) >= 0)
    {
        res = rup % 100;
        result = result + " " + RupeesToWords(res);
    }
    result = result + ' ' + " Rupees only";
    return result;
    }
    public string RupeesToWords(Int64 rup)
    {
        string result="";
        if ((rup >= 1) && (rup <= 10))
        {
            if ((rup % 10) == 1) result = "One";
            if ((rup % 10) == 2) result = "Two";
            if ((rup % 10) == 3) result = "Three";
            if ((rup % 10) == 4) result = "Four";
            if ((rup % 10) == 5) result = "Five";
            if ((rup % 10) == 6) result = "Six";
            if ((rup % 10) == 7) result = "Seven";
            if ((rup % 10) == 8) result = "Eight";
            if ((rup % 10) == 9) result = "Nine";
            if ((rup % 10) == 0) result = "Ten";
        }
        if (rup > 9 && rup < 20)
        {
            if (rup == 11) result = "Eleven";
            if (rup == 12) result = "Twelve";
            if (rup == 13) result = "Thirteen";
            if (rup == 14) result = "Forteen";
            if (rup == 15) result = "Fifteen";
            if (rup == 16) result = "Sixteen";
            if (rup == 17) result = "Seventeen";
            if (rup == 18) result = "Eighteen";
            if (rup == 19) result = "Nineteen";
        }
        if (rup > 20 && (rup / 10) == 2 && (rup % 10) == 0) result = "Twenty";
        if (rup > 20 && (rup / 10) == 3 && (rup % 10) == 0) result = "Thirty";
        if (rup > 20 && (rup / 10) == 4 && (rup % 10) == 0) result = "Forty";
        if (rup > 20 && (rup / 10) == 5 && (rup % 10) == 0) result = "Fifty";
        if (rup > 20 && (rup / 10) == 6 && (rup % 10) == 0) result = "Sixty";
        if (rup > 20 && (rup / 10) == 7 && (rup % 10) == 0) result = "Seventy";
        if (rup > 20 && (rup / 10) == 8 && (rup % 10) == 0) result = "Eighty";
        if (rup > 20 && (rup / 10) == 9 && (rup % 10) == 0) result = "Ninty";

        if (rup > 20 && (rup / 10) == 2 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Twenty One";
            if ((rup % 10) == 2) result = "Twenty Two";
            if ((rup % 10) == 3) result = "Twenty Three";
            if ((rup % 10) == 4) result = "Twenty Four";
            if ((rup % 10) == 5) result = "Twenty Five";
            if ((rup % 10) == 6) result = "Twenty Six";
            if ((rup % 10) == 7) result = "Twenty Seven";
            if ((rup % 10) == 8) result = "Twenty Eight";
            if ((rup % 10) == 9) result = "Twenty Nine";
        }
        if (rup > 20 && (rup / 10) == 3 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Thirty One";
            if ((rup % 10) == 2) result = "Thirty Two";
            if ((rup % 10) == 3) result = "Thirty Three";
            if ((rup % 10) == 4) result = "Thirty Four";
            if ((rup % 10) == 5) result = "Thirty Five";
            if ((rup % 10) == 6) result = "Thirty Six";
            if ((rup % 10) == 7) result = "Thirty Seven";
            if ((rup % 10) == 8) result = "Thirty Eight";
            if ((rup % 10) == 9) result = "Thirty Nine";
        }
        if (rup > 20 && (rup / 10) == 4 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Forty One";
            if ((rup % 10) == 2) result = "Forty Two";
            if ((rup % 10) == 3) result = "Forty Three";
            if ((rup % 10) == 4) result = "Forty Four";
            if ((rup % 10) == 5) result = "Forty Five";
            if ((rup % 10) == 6) result = "Forty Six";
            if ((rup % 10) == 7) result = "Forty Seven";
            if ((rup % 10) == 8) result = "Forty Eight";
            if ((rup % 10) == 9) result = "Forty Nine";
        }
        if (rup > 20 && (rup / 10) == 5 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Fifty One";
            if ((rup % 10) == 2) result = "Fifty Two";
            if ((rup % 10) == 3) result = "Fifty Three";
            if ((rup % 10) == 4) result = "Fifty Four";
            if ((rup % 10) == 5) result = "Fifty Five";
            if ((rup % 10) == 6) result = "Fifty Six";
            if ((rup % 10) == 7) result = "Fifty Seven";
            if ((rup % 10) == 8) result = "Fifty Eight";
            if ((rup % 10) == 9) result = "Fifty Nine";
        }
        if (rup > 20 && (rup / 10) == 6 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Sixty One";
            if ((rup % 10) == 2) result = "Sixty Two";
            if ((rup % 10) == 3) result = "Sixty Three";
            if ((rup % 10) == 4) result = "Sixty Four";
            if ((rup % 10) == 5) result = "Sixty Five";
            if ((rup % 10) == 6) result = "Sixty Six";
            if ((rup % 10) == 7) result = "Sixty Seven";
            if ((rup % 10) == 8) result = "Sixty Eight";
            if ((rup % 10) == 9) result = "Sixty Nine";
        }
        if (rup > 20 && (rup / 10) == 7 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Seventy One";
            if ((rup % 10) == 2) result = "Seventy Two";
            if ((rup % 10) == 3) result = "Seventy Three";
            if ((rup % 10) == 4) result = "Seventy Four";
            if ((rup % 10) == 5) result = "Seventy Five";
            if ((rup % 10) == 6) result = "Seventy Six";
            if ((rup % 10) == 7) result = "Seventy Seven";
            if ((rup % 10) == 8) result = "Seventy Eight";
            if ((rup % 10) == 9) result = "Seventy Nine";
        }
        if (rup > 20 && (rup / 10) == 8 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Eighty One";
            if ((rup % 10) == 2) result = "Eighty Two";
            if ((rup % 10) == 3) result = "Eighty Three";
            if ((rup % 10) == 4) result = "Eighty Four";
            if ((rup % 10) == 5) result = "Eighty Five";
            if ((rup % 10) == 6) result = "Eighty Six";
            if ((rup % 10) == 7) result = "Eighty Seven";
            if ((rup % 10) == 8) result = "Eighty Eight";
            if ((rup % 10) == 9) result = "Eighty Nine";
        }
        if (rup > 20 && (rup / 10) == 9 && (rup % 10) != 0)
        {
            if ((rup % 10) == 1) result = "Ninty One";
            if ((rup % 10) == 2) result = "Ninty Two";
            if ((rup % 10) == 3) result = "Ninty Three";
            if ((rup % 10) == 4) result = "Ninty Four";
            if ((rup % 10) == 5) result = "Ninty Five";
            if ((rup % 10) == 6) result = "Ninty Six";
            if ((rup % 10) == 7) result = "Ninty Seven";
            if ((rup % 10) == 8) result = "Ninty Eight";
            if ((rup % 10) == 9) result = "Ninty Nine";
        }
        return result;
    }

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.