HOW TO CONVERT INDIAN CURRENCY TO WORDS IN ASP.NET C#

in programming •  6 years ago 

HERE IN THIS .Net Tutorial WE WILL CONVERT INDIAN CURRENCY TO WORDS IN ASP.NET C#

SEE CODE BELOW


Step 1 :-WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication13.WebForm1" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

<style type="text/css">

.auto-style1 {

width: 54%;

}

.auto-style2 {

width: 131px;

}

.auto-style3 {

width: 342px;

}

</style>

</head>

<body>

    <form id="form1" runat="server">

        <div>

         <table class="auto-style1">

<tr>

<td class="auto-style2">

<asp:Label ID="Label1" runat="server" Text="Enter  Number:- "></asp:Label>

</td>

<td class="auto-style3">

<asp:TextBox ID="TextBox1" runat="server" Width="302px"></asp:TextBox>

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">&nbsp;</td>

<td class="auto-style3">

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

</td>

<td>&nbsp;</td>

</tr>

<tr>

<td class="auto-style2">&nbsp;</td>

<td class="auto-style3">

<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="XX-Large"></asp:Label>

</td>

<td>&nbsp;</td>

</tr>

</table>

        </div>

    </form>

</body>

</html>


Step 2 :- C# Code


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


namespace WebApplication13

{

public partial class WebForm1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{


}


protected void Button1_Click(object sender, EventArgs e)

{

string word ="RUPEES " + ConvertNumbertoWords(Convert.ToInt32(TextBox1.Text))+" ONLY";

Label2.Text = word;

}


public static string ConvertNumbertoWords(int number)

{

if (number == 0)

return "ZERO";

if (number < 0)

return "minus " + ConvertNumbertoWords(Math.Abs(number));

string words = "";


//if ((number / 1000000000) > 0)

//{

//    words += ConvertNumbertoWords(number / 1000000000) + " Billion ";

//    number %= 1000000000;

//}


if ((number / 100000000) > 0 || (number / 10000000) > 0)

{

if ((number / 10000000) > 0)

{

words += ConvertNumbertoWords(number / 10000000) + " CRORE ";

number %= 10000000;

}

if ((number / 100000000) > 0)

{

words += ConvertNumbertoWords(number / 100000000) + " CRORE ";

number %= 100000000;

}

}


if ((number / 1000000) > 0 || (number / 100000) > 0)

{

if ((number / 100000) > 0)

{

words += ConvertNumbertoWords(number / 100000) + " LAKH ";

number %= 100000;

}

if ((number / 1000000) > 0)

{

words += ConvertNumbertoWords(number / 1000000) + " LAKH ";

number %= 1000000;

}


}

if ((number / 1000) > 0)

{

words += ConvertNumbertoWords(number / 1000) + " THOUSAND ";

number %= 1000;

}

if ((number / 100) > 0)

{

words += ConvertNumbertoWords(number / 100) + " HUNDRED ";

number %= 100;

}

if (number > 0)

{

if (words != "")

words += "AND ";

var unitsMap = new[] { "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE",

"THIRTEEN", "FOURTEEN","FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" };

var tensMap = new[] { "ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY" };


if (number < 20)

words += unitsMap[number];

else

{

words += tensMap[number / 10];

if ((number % 10) > 0)

words += " " + unitsMap[number % 10];

}

}

return words;

}

}

}



If You Haven't Subscribers My Channel Than Please Subscribers It And Even Share It Link Of My Channnel :- https://www.youtube.com/channel/UCdIDIGUh3rL9A_Yt_tbZmkg Please Go And Subscribers It
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

If You Haven't Subscribers My Channel Than Please Subscribers It And Even Share It Link Of My Channnel :- https://www.youtube.com/channel/UCdIDIGUh3rL9A_Yt_tbZmkg Please Go And Subscribers It