Hello Friends,
In these tutorials i'm going to show you how to convert number into words.
HTML Markup : Design Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Numbertowords.aspx.cs" Inherits="ASPNET_Numbertowords" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <b>Enter Amount : </b></b><asp:TextBox ID="txt_number" runat="server" Width="311px"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text=" InWords " onclick="Button1_Click" /> </div> <asp:Label ID="lblresult" runat="server" Text=""></asp:Label> </form> </body> </html>
C# Coding
C# Coding : Namespace
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
C# Coding : Button Click Event
public partial class ASPNET_Numbertowords : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { string converttowords = Inwords(Convert.ToInt32(txt_number.Text.Trim())); lblresult.Text = "< br/>< br/>< br/>< b>< font color='#0000cc'>Amount InWords : < /font>< u>< font color='#ff0000'>" + converttowords + "< /font>< /u>< /b> Rupees Only."; } public static string Inwords(int n) { if (n == 0) return "ZERO"; if (n < 0) return "minus " + Inwords(Math.Abs(n)); string inwords = ""; if ((n / 10000000) > 0) { inwords += Inwords(n / 10000000) + " CRORE "; n = n % 10000000; } if ((n / 100000) > 0) { inwords += Inwords(n / 100000) + " LAKH "; n = n % 100000; } if ((n / 1000) > 0) { inwords += Inwords(n / 1000) + " THOUSAND "; n = n % 1000; } if ((n / 100) > 0 || (n / 1000) < 0) { inwords += Inwords(n / 100) + " HUNDRED "; n = n % 100; } if (n > 0) { if (inwords != "") inwords += "AND "; var units = new[] { "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" }; var tens = new[] { "ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY" }; if (n < 20) inwords += units[n]; else { inwords += tens[n / 10]; if ((n % 10) > 0) inwords += " " + units[n % 10]; } } return inwords; } }
0 Comments