# Convert Numeric Currency into Words (For INDIAN Currency Only) (Optimized)

, 6 Sep 2011 CPOL
 Rate this:
Converts from 0(zero) to 10^39(adant-shinghar) into words. E.g. 70250 into seventy thousand two hundred fifty

## Introduction

This is a simple program or a complicated one too that converts numeric value into words from 0 to 1039;... Great!!!

A Short introduction may be:

It can convert 0 to Zero, can also convert to 12345 to "twelve thousand three hundred forty five" and can also covert 1039 to 1 Adant-Shinghar. (Courtesy: Wikipedia for providing me with the notations.)

Before you move further, let me inform you first that this class will give you a returned value in `string `with HTML tags attached, so please use it for web application so that you will find neat and clean results and to use it for Windows Forms, please make the necessary changes.

So guys, let's dive into the logic !!!

## Background

Below is a snap shot provided to get the following results.

## Using the Code

Let's dig into the code step by step.

### Step 1

Take three `static List<DictionaryEntry> `Type objects for static data storage and load that in the constructor of class.

Have a look at the code snippets.

Constructor of the class:

```namespace Hirs.IndianNumericToWordConverter
{
public class IndiaCurrencyConverter
{
private Hashtable htPunctuation;
private Dictionary<int> DictStaticSuffix;
private Dictionary<int> DictStaticPrefix;
private Dictionary<int> DictHelpNotation;
private System.Drawing.Color color;

public IndiaCurrencyConverter()
{
htPunctuation = new Hashtable();
DictStaticPrefix = new Dictionary<int>();
DictStaticSuffix = new Dictionary<int>();
DictHelpNotation = new Dictionary<int>();
Native = native;
}```

Here is the method that loads `static `data with values.

```private void LoadStaticSuffix()
{
}
{
}
{
(9, "=1,00,00,00,00,00,00,00,000 (17 Trailing Zeros)");
(19 Trailing Zeros)");
(21 Trailing Zeros)");
(23 Trailing Zeros)");
(25 Trailing Zeros)");
(27 Trailing Zeros)");
(29 Trailing Zeros)");
(16, "=1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000
(31 Trailing Zeros)");
(17, "=1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000
(33 Trailing Zeros)");
(18, "=1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000
(35 Trailing Zeros)");
(19, "=1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000
(37 Trailing Zeros)");
(20, "=1,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,000
(39 Trailing Zeros)");
}```

and I got comments on what is needed of `List<DictionaryEntry> listHelpNotation `so, the reason behind that is on Hovering you can get help its unit values.

### Step 2

Now insert Input value (Let me notify you that input value will be in `string `because no datatype supports 1039).

Assume input value is 123456789.

First reverse the input string:

(987654321)

Then split and insert reversed string into hashtable (first 3 digit, and then after 2 till end):

(987,65,43,21)

and then reverse every splitted value inserted into hashtable so that it makes real sense.

(789,56,34,12)

and insert that to hashtable with key value pair using the following code:

```private void InsertToPunctuationTable(string strValue)
{
int j = 2;
for (int i = 3; i < strValue.Length; i = i + 2)
{
if (strValue.Substring(i).Length > 0)
{
if (strValue.Substring(i).Length >= 2)
else
}
else
break;
j++;

}
}```

Now get the word notation for every value stored in hashtable descending.

Have a look at the code.

Here's the function:

`GetWordConversion(string inputNumber)`

It takes `Stringconverted `numeric value and gives its Word Conversation, It will take input which will have a maximum of 3 digits. You may remember from the upper hashtable that Entry has value which is maximum of 3 digits.

#### Explanation of Condition Check

`if (int.Parse(inputNumber.Substring(0, 1)) > 0)`

Checks if the first digit is not zero, then return Hundreds notation. E.g. 434 then it returns Four Hundred

`string TempString = StaticSuffixFind(inputNumber.Substring(1, 2));`

This condition checks that if the two digit value is already stored in List. E.g., it will return twelve with input of 12. Rather than returning One Two, and if it is 34 then No stored value will be found and it will pass the condition `if(tempString == "")` and will move on. The different condition will be applied to if the number is Two digit, or 1 digit.

```private string GetWordConversion(string inputNumber)
{
string ToReturnWord = String.Empty;
if (inputNumber.Length <= 3 && inputNumber.Length > 0)
{
if (inputNumber.Length == 3)
{
if (int.Parse(inputNumber.Substring(0, 1)) > 0)
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(0, 1)) + "Hundred ";

string TempString = StaticSuffixFind(inputNumber.Substring(1, 2));

if (TempString == "")
{
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(1, 1) + "0");
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(2, 1));
}
ToReturnWord = ToReturnWord + TempString;
}
if (inputNumber.Length == 2)
{
string TempString = StaticSuffixFind(inputNumber.Substring(0, 2));
if (TempString == "")
{
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(0, 1) + "0");
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(1, 1));
}
ToReturnWord = ToReturnWord + TempString;
}
if (inputNumber.Length == 1)
{
ToReturnWord = ToReturnWord +
StaticSuffixFind(inputNumber.Substring(0, 1));
}
}
}```

After that, attach the following splitted words from the splitted hashtable value and their notation and make the one big `string `that will depict the whole notation:

```private string ReturnHashtableValue()
{
string strFinalString = String.Empty;
for (int i = htPunctuation.Count; i > 0; i--)
{
if (GetWordConversion((htPunctuation[i]).ToString()) != "")
strFinalString = strFinalString +
GetWordConversion((htPunctuation[i]).ToString()) +
StaticPrefixFind((i).ToString());
}
return strFinalString;
}```

## Points of Interest

For now, I have submitted code for Indian currency only. Now for moving further in part-II, I will also depict how to covert in international currency as suggested by Indian mentors from Indian forums.

FYI, Part-II is published. Have a look:

And last but not the least, thanks to the audience for giving your votes and valuable time.

For further details, please see the attached class.

## History

• This is Part-I. Part-II has been submitted for international currency.

## Share

Software Developer
India
He is a Smart IT devloper with Few years of Expeariance But having Great command on ASP.net,C#,SQL Query,SSRS,Crystal Reports

Apart from that He Loves multimedia work too, Master of Adobe photoshop, Illustrator, CSS , HTML and all things.

He is Currently working in Microsoft Dynamics CRM and Having Nice Expearince with CRM. CRM Rocks!!!

 First PrevNext
 Q 1 sofyan_fly 25-Jan-13 3:17
 Re: Q 1 Hiren solanki 24-Mar-14 6:31
 Thanks rahulkanojia2002 6-Sep-12 21:22
 My vote of 4 manoj kumar choubey 2-Feb-12 23:46
 My vote of 5 GPUToaster™ 4-Oct-11 2:26
 Works only till 999 arunglobal 23-Aug-11 21:43
 Re: Works only till 999 Hiren solanki 5-Sep-11 2:08
 [My vote of 1] OMG i've never seen... Selvin 27-Dec-10 1:54
 Re: [My vote of 1] OMG i've never seen... Hiren Solanki 27-Dec-10 1:58
 good work Pranay Rana 15-Dec-10 21:16
 Re: good work Hiren Solanki 15-Dec-10 21:17
 My vote of 5 GPUToaster 20-Oct-10 2:07
 Re: My vote of 5 Hiren Solanki 28-Oct-10 1:49
 Good one Hiren! Sushant Joshi 22-Sep-10 20:46
 Re: Good one Hiren! Hiren Solanki 22-Sep-10 20:49
 My vote of 5 Prosanta Kundu online 12-Sep-10 19:33
 Re: My vote of 5 Hiren Solanki 12-Sep-10 20:31
 My vote of 2 [modified] Nagy Vilmos 10-Sep-10 4:23
 Re: My vote of 2 Abhijit Jana 10-Sep-10 8:14
 Re: My vote of 2 KunalChowdhury 10-Sep-10 8:57
 Re: My vote of 2 Abhijit Jana 10-Sep-10 9:27
 Re: My vote of 2 Hiren Solanki 10-Sep-10 18:12
 Re: My vote of 2 [modified] Hiren Solanki 10-Sep-10 20:11
 My vote of 3 karabax 1-Sep-10 7:00
 Re: My vote of 3 Hiren Solanki 5-Sep-10 20:30
 Re: My vote of 3 S M P 9-Sep-10 3:26
 Re: My vote of 3 Hiren Solanki 9-Sep-10 3:51
 Re: My vote of 3 KunalChowdhury 9-Sep-10 20:56
 Re: My vote of 3 Hiren Solanki 9-Sep-10 21:01
 Re: My vote of 3 Abhinav S 9-Sep-10 21:05
 Re: My vote of 3 KunalChowdhury 9-Sep-10 21:06
 Re: My vote of 3 Hiren Solanki 9-Sep-10 21:08
 Re: My vote of 3 KunalChowdhury 9-Sep-10 21:10
 Re: My vote of 3 KunalChowdhury 9-Sep-10 21:11
 Re: My vote of 3 Hiren Solanki 9-Sep-10 21:13
 Re: My vote of 3 Nagy Vilmos 10-Sep-10 4:14
 Re: My vote of 3 Hiren Solanki 10-Sep-10 4:19
 Nice one HimanshuJoshi 1-Sep-10 4:53
 Re: Nice one Hiren Solanki 5-Sep-10 20:30
 Re: Nice one Nagy Vilmos 10-Sep-10 4:23
 Re: Nice one Hiren Solanki 10-Sep-10 4:26
 Re: Nice one HimanshuJoshi 10-Sep-10 5:04
 Re: Nice one Nagy Vilmos 10-Sep-10 5:14
 Re: Nice one Hiren Solanki 10-Sep-10 5:21
 Re: Nice one HimanshuJoshi 10-Sep-10 4:58
 Re: Nice one Nagy Vilmos 10-Sep-10 5:19
 My vote of 5 Viral Upadhyay 1-Sep-10 2:55
 Re: My vote of 5 Hiren Solanki 5-Sep-10 20:29
 My vote of 4 S M P 1-Sep-10 0:26
 Re: My vote of 4 Hiren Solanki 1-Sep-10 0:37
 Last Visit: 31-Dec-99 19:00     Last Update: 20-Dec-14 11:24 Refresh 12 Next »