Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / C#

Convert Numeric Currency into Words for International Currency - Part - II (Optimized)

Rate me:
Please Sign up or sign in to vote.
4.81/5 (14 votes)
12 Sep 2010CPOL1 min read 52.1K   810   12   12
Converts numeric currency in words with two modes - international and Indian. e.g., 1000000 to ten Lacs (for India) one million (for international)

Introduction

So after a long (almost 13 days) time, I am going to take my article to the next level.

Have a look at my previous article:

First walk through the base article. In this article, you will find extension only to that article.

Background

Let's have a look at the snapshots.

For Indian

indiaConversion.JPG

For International

foreignconversio.JPG

Using the Code

So let me start by depicting the extension points to the previous article.

First, I have added one enumeration, which is about to be passed at the constructor of the class and will be set to global variable for program to know in which type to convert.

C#
public enum Criteria
{
    Indian,
    Foreign
}

Another change is in which pattern data is to be filled to hashtable.

E.g.

In Indian currency, you can split 234445443345345 into 23,44,45,44,33,45,345 ( I mean first group of three digit and then 2 digits).

In foreign currency, you can split 234445443345345 into 234,445,443,345,345 (I mean groups of three digits).

So as per that, I will also need to change the way data is filling to hashtable.

Take a look:

C#
private void InsertToPunctuationTable(string strValue)
{
    int j = 0;
    if (Native == Criteria.Indian)
    {
        htPunctuation.Add(1, strValue.Substring(0, 3).ToString());
        j = 2;
        for (int i = 3; i < strValue.Length; i = i + 2)
        {
            if (strValue.Substring(i).Length > 0)
            {
                if (strValue.Substring(i).Length >= 2)
                    htPunctuation.Add(j, strValue.Substring(i, 2).ToString());
                else
                    htPunctuation.Add(j, strValue.Substring(i, 1).ToString());
            }
            else
                break;
            j++;                    
        }
    }
    if (Native == Criteria.Foreign)
    {
        for (int i = 0; i < strValue.Length; i = i + 3)
        {
            if (strValue.Substring(i).Length > 0)
            {
                if (strValue.Substring(i).Length >= 3)
                    htPunctuation.Add(j, strValue.Substring(i, 3).ToString());
                else
                    htPunctuation.Add(j, strValue.Substring(i).ToString());
            }
            j++;
        }
    }
}

For Indian currency, I have depicted hashtable picture in the previous article. Now take a look at the hashtable data on foreign condition:

hashtablePic.JPG

Same way differentiate Notation.

C#
private void LoadStaticPrefix()
        {
            if (Native == Criteria.Indian)
            {
                DictStaticPrefix.Add(2, "Thousand ");
                DictStaticPrefix.Add(3, "Lac ");
                DictStaticPrefix.Add(4, "Crore ");
                DictStaticPrefix.Add(5, "Arab ");
                DictStaticPrefix.Add(6, "Kharab ");
                DictStaticPrefix.Add(7, "Neel ");
                DictStaticPrefix.Add(8, "Padma ");
                DictStaticPrefix.Add(9, "Shankh ");
                DictStaticPrefix.Add(10, "Maha-shankh ");
                DictStaticPrefix.Add(11, "Ank ");
                DictStaticPrefix.Add(12, "Jald ");
                DictStaticPrefix.Add(13, "Madh ");
                DictStaticPrefix.Add(14, "Paraardha ");
                DictStaticPrefix.Add(15, "Ant ");
                DictStaticPrefix.Add(16, "Maha-ant ");
                DictStaticPrefix.Add(17, "Shisht ");
                DictStaticPrefix.Add(18, "Singhar ");
                DictStaticPrefix.Add(19, "Maha-singhar ");
                DictStaticPrefix.Add(20, "Adant-singhar ");
            }
            if (Native == Criteria.Foreign)
            {
                DictStaticPrefix.Add(1, "Thousand ");
                DictStaticPrefix.Add(2, "Million ");
                DictStaticPrefix.Add(3, "Billion ");
                DictStaticPrefix.Add(4, "Trillion ");
                DictStaticPrefix.Add(5, "Quadrillion ");
                DictStaticPrefix.Add(6, "Quintillion ");
                DictStaticPrefix.Add(7, "Sextillion ");
                DictStaticPrefix.Add(8, "Septillion ");
                DictStaticPrefix.Add(9, "Octillion ");
                DictStaticPrefix.Add(10, "Nonillion ");
                DictStaticPrefix.Add(11, "Decillion ");
                DictStaticPrefix.Add(12, "Undecillion ");
                DictStaticPrefix.Add(13, "Duodecillion ");
            }
        }

These all are extensions to the previous article, rest is the same as previous.

Points of Interest

This is Part-II, if anybody wants it in another notation as well, give me the notation, will I publish it as part-III.

History

  • 10th September, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India 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!!!

Comments and Discussions

 
Questioninternational currency.in word Pin
Shubham @R$8-Aug-14 0:35
Shubham @R$8-Aug-14 0:35 
GeneralMy vote of 5 Pin
thatraja19-Sep-10 20:10
professionalthatraja19-Sep-10 20:10 
GeneralRe: My vote of 5 Pin
Hiren solanki19-Sep-10 20:17
Hiren solanki19-Sep-10 20:17 
GeneralMy vote of 2 PinPopular
karabax10-Sep-10 5:52
karabax10-Sep-10 5:52 
GeneralRe: My vote of 2 [modified] Pin
Hiren solanki10-Sep-10 17:01
Hiren solanki10-Sep-10 17:01 
Generalgr8 Pin
Peace ON10-Sep-10 5:39
Peace ON10-Sep-10 5:39 
GeneralRe: gr8 Pin
Hiren solanki10-Sep-10 21:03
Hiren solanki10-Sep-10 21:03 
GeneralSuper Pin
Kunal Chowdhury «IN»10-Sep-10 5:04
professionalKunal Chowdhury «IN»10-Sep-10 5:04 
GeneralRe: Super Pin
Hiren solanki10-Sep-10 21:03
Hiren solanki10-Sep-10 21:03 
GeneralRe: Super Pin
Kunal Chowdhury «IN»10-Sep-10 21:07
professionalKunal Chowdhury «IN»10-Sep-10 21:07 
GeneralRe: Super Pin
Hiren solanki10-Sep-10 21:08
Hiren solanki10-Sep-10 21:08 
GeneralRe: Super Pin
Kunal Chowdhury «IN»10-Sep-10 21:16
professionalKunal Chowdhury «IN»10-Sep-10 21:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.