Friday, March 29, 2013

Converting Numbers to Words in C# (OR ) how to convert number into words in C#

In this post i will show how to convert numbers (integers, decimals) to words as shown below.

EX :   1008  ==> Indian Currency : One Thousand Eight Rupee(s) And Zero Paise Only.
                             Dollars : One Thousand Eight Dollars(s) And Zero Cents Only.

Out Put : 

 ASPX.Net :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Numbers2Words.aspx.cs"
    Inherits="DT_Pagination.Numbers2Words1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
        <br />
        <asp:Label ID="lblWordsIndianCurrency" runat="server" Text="N/A"></asp:Label>
        <br />
        <asp:Label ID="lblWordsDollar" runat="server" Text="N/A"></asp:Label>
        <br />
        <asp:Button ID="btnConvert" runat="server" Text="Convert" OnClick="btnConvert_Click" />

C# Class : 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DT_Pagination
    public partial class Numbers2Words1 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        protected void btnConvert_Click(object sender, EventArgs e)
            decimal deci = Convert.ToDecimal(txtNumber.Text.Trim());
            Numbers2Words N2W = new Numbers2Words();
            string val = "";
            string val1 = "";
            val = N2W.Num2WordConverter(deci.ToString(), "RS").ToString();
            val1 = N2W.Num2WordConverter(deci.ToString(), "").ToString();
            lblWordsIndianCurrency.Text = "<b>Indian Currency : </b>"+val;
            lblWordsDollar.Text = "<b>Dollars : </b>"+val1;

 DownLoad Class From HERE

1 comment:

  1. Useful information.. but one minor error is namespace DT_Pagination..Delete this from all pages.. Then it works fine..Thank you Vara Reddy..