Click here to Skip to main content
Click here to Skip to main content

Tagged as

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

, 12 Sep 2010
Rate this:
Please Sign up or sign in to vote.
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.

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:

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.

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)

Share

About the Author

Hiren solanki
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 PinmemberMember 109683668-Aug-14 0:35 
GeneralMy vote of 5 Pinmemberthatraja19-Sep-10 20:10 
GeneralRe: My vote of 5 PinmemberHiren Solanki19-Sep-10 20:17 
GeneralMy vote of 2 Pinmemberkarabax10-Sep-10 5:52 
GeneralRe: My vote of 2 [modified] PinmemberHiren Solanki10-Sep-10 17:01 
Generalgr8 PinmemberJinal Desai - LIVE10-Sep-10 5:39 
GeneralRe: gr8 PinmemberHiren Solanki10-Sep-10 21:03 
GeneralSuper PinmentorKunalChowdhury10-Sep-10 5:04 
GeneralRe: Super PinmemberHiren Solanki10-Sep-10 21:03 
GeneralRe: Super PinmentorKunalChowdhury10-Sep-10 21:07 
GeneralRe: Super PinmemberHiren Solanki10-Sep-10 21:08 
GeneralRe: Super PinmentorKunalChowdhury10-Sep-10 21:16 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 13 Sep 2010
Article Copyright 2010 by Hiren solanki
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid