MD. ROFIQUL ISLAM


Md. Rofiqul Islam is a Software Engineer of ASA International a world renowned Microfinance Organization originated in Bangladesh. He completed B.Sc. and M.Sc. in Information & Communication Engineering (ICE) from Islamic University, Bangladesh. He is experienced in Microsoft Technology such as Asp.net/C#, ASP.Net MVC, SQL Server, and Object Oriented Analysis and Design. He is an Microsoft Certified Technology Specialist (MCTS) and Certified Ethical Hacker (CEH),he has more than 7 years of working experience in Microsoft technology.


Articles Archives
March, 2017 (1)
December, 2016 (1)
November, 2016 (1)
October, 2016 (1)
September, 2016 (1)
August, 2016 (1)
December, 2015 (1)

P_Article

Number to words in C#

Introduction

In this tip, I am trying to give a solution for converting numbers to words. It is very essential for software developers. For financial solutions, we may need to translate into words, e.g., in a receipt, voucher, cheque print, etc. We can do it in C#, SQL Server, Crystal Reports. In this regard, I gave a solution in C#, SQL Server, Crystal Reports.

Using the Code

In C#, I used a recursive function in which two string arrays are used for 1 to 99, when the number will be more than 99, the function will call itself recursively.

public static string NumToWordBD(Int64 Num) 
{ 
    string[] Below20 = { "", "One ", 
    "Two ", "Three ", "Four ", 
      "Five ", "Six " , "Seven ", 
      "Eight ", "Nine ", "Ten ", "Eleven ", 
    "Twelve " , "Thirteen ", "Fourteen ","Fifteen ", 
      "Sixteen " , "Seventeen ","Eighteen " , "Nineteen " }; 
    string[] Below100 = { "", "", "Twenty ", "Thirty ", 
      "Forty ", "Fifty ", "Sixty ", 
      "Seventy ", "Eighty ", "Ninety " }; 
    string InWords=""; 
    if(Num >= 1 && Num < 20) 
    InWords += Below20[Num]; 
    if(Num >=20 && Num <= 99) 
    InWords += Below100[Num / 10] + Below20[Num % 10]; 
    if (Num >= 100 && Num <= 999) 
    InWords += NumToWordBD(Num / 100) + " Hundred " + NumToWordBD(Num % 100); 
    if (Num >= 1000 && Num <= 99999) 
    InWords += NumToWordBD(Num / 1000) + " Thousand " + NumToWordBD(Num % 1000); 
    if (Num >= 100000 && Num <= 9999999) 
    InWords += NumToWordBD(Num / 100000) + " Lac " + NumToWordBD(Num % 100000); 
    if (Num >= 10000000) 
    InWords += NumToWordBD(Num / 10000000) + " Crore " + NumToWordBD(Num % 10000000); 
    return InWords;
}

protected override P_Article Map(System.Data.SqlClient.SqlDataReader dataReader)
        {
            P_Article entity = new P_Article();

            entity.Id = DBUtility.ToInt32(dataReader["Id"]);
            entity.P_SubCategoryId = DBUtility.ToInt32(dataReader["P_SubCategoryId"]);
            entity.ShortDescription = DBUtility.ToString(dataReader["ShortDescription"]);
            entity.Title = DBUtility.ToString(dataReader["Title"]);
            entity.Description = DBUtility.ToString(dataReader["Description"]);
            entity.PostingDate = DBUtility.ToDateTime(dataReader["PostingDate"]);
            entity.UpdateDate = DBUtility.ToNullableDateTime(dataReader["UpdateDate"]);
            entity.P_AuthorId = DBUtility.ToInt32(dataReader["P_AuthorId"]);
            entity.Status = DBUtility.ToBoolean(dataReader["Status"]);

            return entity;

        }

Modified Date:Thursday, January 12, 2017
Share on

Md. Rofiqul Islam
M.Sc., MCTS, CEH
Software Engineer, Bangladesh.
I am a learner throughout my life. I have completed BSc & MSc in Information & Communication Engineering from Islamic University, Bangladesh. I am having over 7 years of working experience in Microsoft Technology. I'm fond of learning through sharing knowledge.
Copyright © 2017 Md. Rofiqul Islam, Email: rofiq.ict@gmail.com