Usually when you are working on financial applications, particularly on a Financial Transaction Report Module then their is a need to convert numbers into strings. Suppose their is a bill print module in which you must convert an Amount entered into a textbox to a string then instead of manually entering the Amount, in a word you can directly convert the amount entered to the textbox to a string.
So considering the above requirement have written this article to demonstrate how to convert any number to a string, so let us start it with the Basics.
Introduction
This article is very useful to all particularly who are working on Financial projects but by writing this article I have also focused on Beginners so let us start it with the basics.
What is a String?
A String is a sequence of charcters enclosed within double quatation marks.
Example
"vithal wadje" , "C#" , "Mumbai" "Five hundred" etc.
What is a Number?
Any digits between 0-9 including floats, decimals, numerals which are countable is called a Number.
Example
523656, 452.01 165.00
452.01 165.00 etc.
Now I hope you understand the concept of String and Number. Now we are developing the application to convert these numbers into strings with one financial screen. So let us start it step-by-step.
Create a website as:
- Start - All Programs - Microsoft Visual Studio 2010
- File - New Website-C# - Empty website (to avoid adding a master page)
- Give the web site a name such as ConvertingNumbersToWord and specify the location
- Then right-click on Solution Explorer - Add New Item-Default.aspx page
- Drag a drop one Textbox for entering the value, one button to perform the action and one label to show the results in a <form> tag region
<form id="form1" runat="server">
<table>
<tr>
<td>Enter Amount</td>
</tr>
<tr>
< td >
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ td >
</tr>
<tr>
< td >
<asp:Label ID="Label1" runat="server" Text="Label" BackColor="Gray"
Font-Bold="True" Font-Italic="False" ForeColor="#CC3300"></asp:Label>
</ td >
</tr>
<tr>
< td align="center" >
<asp:Button ID="Button1" runat="server" Text="Convert" onclick="Button1_Click" />
</ td >
</tr>
</table>
</div>
</form>
Then switch to view code and create a method Named Initialize() to hold the strings, as:
private void Initialize()
{
SNu[0] = "";
SNu[1] = "One";
SNu[2] = "Two"; //to hold string related to numbers which is called on page load
SNu[3] = "Three";
SNu[4] = "Four";
SNu[5] = "Five";
SNu[6] = "Six";
SNu[7] = "Seven";
SNu[8] = "Eight";
SNu[9] = "Nine";
SNu[10] = "Ten";
SNu[11] = "Eleven";
SNu[12] = "Twelve";
SNu[13] = "Thirteen";
SNu[14] = "Fourteen";
SNu[15] = "Fifteen";
SNu[16] = "Sixteen";
SNu[17] = "Seventeen";
SNu[18] = "Eighteen";
SNu[19] = "Nineteen";
SNt[2] = "Twenty";
SNt[3] = "Thirty";
SNt[4] = "Forty";
SNt[5] = "Fifty";
SNt[6] = "Sixty";
SNt[7] = "Seventy";
SNt[8] = "Eighty";
SNt[9] = "Ninety";
US[1] = "";
US[2] = "Thousand";
US[3] = "Million";
US[4] = "Billion";
US[5] = "Trillion";
US[6] = "Quadrillion";
US[7] = "Quintillion";
US[8] = "Sextillion";
US[9] = "Septillion";
US[10] = "Octillion";
}
and call this method on page load as:
protected void Page_Load(object sender, EventArgs e)
{
Initialize(); //calling string method
}
Then double-click on the button and use this code for the button click event:
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "")
{
Label1.Text = "Enter Amount";
}
else
{
string currency = "Rupees "; // for adding a prefix before converted string
if (Convert.ToDouble(TextBox1.Text) == 0)
{
Label1.Text = "Null Value"; //if user enters null value
return;
}
if (Convert.ToDouble(TextBox1.Text) < 0)
{
Label1.Text = "Invalid Value";
return;
}
string[] no = TextBox1.Text.Split('.');
if ((no[0] != null) && (no[1] != "00")) //spliting the texbox value to check if any decimal point is added after number
{
Number = no[0]; deciml = no[1 ];
_number = (NameOfNumber(Number));
_deciml = (NameOfNumber(deciml ));
Label1.Text = currency + _number.Trim() + " and " + _deciml.Trim() + currency;
}
if ((no[0] != null) && (no[1] == "00")) // check if user does not input decimal, value
{
Number = no[0];
_number = (NameOfNumber(Number));
Label1.Text = currency + _number + "Only"; // showing whole result with suffix
}
if ((Convert.ToDouble(no[0]) == 0) && (no[1] != null))
{
deciml = no[1];
_deciml = (NameOfNumber(deciml));
Label1.Text = _deciml + currency;
}
For more code please download the sample application zip file, then run the application and input a value into the textbox which looks as in the following image:

So the output of the application is as shown in the above image after running the application.
Note
When you enter the value in the textbox enter with decimal points.
Example
5823.00 , 45215.54 etc.
Summary
The above article is very useful in any project depending on your requirements, for both beginner as well as intermediate readers to understand. I have provided more examples with explanations and comments..I hope this article helps all readers. If you have any suggestion then please contact me.

Abhijeet ThanekarPosted Sep 24, 2015, 2:20 AM
Its Not Working If U give amount 100000.00 O/P:One hundred Thousand Only
Vithal WadjeeditedPosted Oct 29, 2012, 7:16 AMEdited Oct 29, 2012, 8:34 AM
yes sir sure,next time i will take care of this thank you for your valuable suggestion.
Praveen VReditedPosted Oct 29, 2012, 7:11 AMEdited Oct 29, 2012, 7:13 AM
OK Vithal..Its nice to hear from you..Please make a "Note:" on such case if such complex scenario you have. Because that was the major function doing the action.
Vithal WadjeeditedPosted Oct 29, 2012, 4:57 AMEdited Oct 29, 2012, 4:58 AM
dear Praveen vr sir, you can download source code and see the all functions that i have commented each line for reader understanding and also see results by running this application. it is not possible to write all methods ,classes in article section due to the complexity.
Praveen VReditedPosted Oct 29, 2012, 2:48 AMEdited Oct 29, 2012, 2:52 AM
Where is the NameOfNumber() function you defined ????
Vithal WadjePosted Oct 26, 2012, 6:04 AM
no Tina madam,i have already reduced the complexity of applicatin, by using the small code you can convert many Billions value into string.
Vithal WadjePosted Oct 26, 2012, 6:02 AM
thanks olive,its my pleasure
Tina GargPosted Oct 25, 2012, 11:58 PM
Is their any class for which we convert number to string in c#..So that it reduce the complexity of the program...?
olive olivePosted Oct 25, 2012, 11:28 PM
By reading this article, now I can easily convert a numeric value into string value.