You must Sign In to post a response.
  • Category: .NET

    Need detail amount conversion

    Dear Friends
    I want to convert amount to our indian currency formate
    ex: 11.50 means it should be show leven and fifty paise only
    11 means it should be show leven only
  • #764335
    So you need to covert number to word format. refer below snippet

    public static string ConvertToWords(int number)
    {
    switch (number)
    {
    case 0:
    return "Zero";
    case 1:
    return "One";
    ...
    case 568:
    return "Five hundred and sixty-eight";
    case 569:
    return "Five hundred and sixty-nine";
    }
    throw new ArgumentOutOfRangeException("Number greater than infinity!");
    }
    line wise you can define the number and return string from it
    look at below link
    http://www.codeproject.com/Tips/103025/Converting-numbers-to-the-word-equivalent

    OR
    Here is the numbertoWords class that is useful to convert it
    http://midnightprogrammer.net/file.axd?file=2009/5/Num2Wrd.cs
    and you can use it as below
    http://midnightprogrammer.net/post/convert-numbers-to-words-in-c

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764336
    Please try below code:

    protected void Page_Load(object sender, EventArgs e)
    {
    System.Globalization.CultureInfo info = System.Globalization.CultureInfo.GetCultureInfo("en-IN");
    decimal number = (11.50M);
    // decimal number = (11M);

    string[] data = number.ToString().Split('.');
    string data1 = words(Convert.ToInt32(data[0]));
    if (data.Length == 1)
    {
    if (data1.StartsWith("and"))
    data1 = data1.Replace("and", "");
    Response.Write(data1);
    }

    else
    {
    if (data[1] != "" && data[1] != "0")
    {
    string data2 = words(Convert.ToInt32(data[1]));

    if (data1.StartsWith("and"))
    data1 = data1.Replace("and", "");
    Response.Write(data1 + " " + data2 + " Paisa");
    }
    else
    Response.Write(data1.Replace("and", ""));

    }
    }
    public string words(int numbers)
    {
    int number = numbers;

    if (number == 0) return "Zero";
    if (number == -2147483648) return "Minus Two Hundred and Fourteen Crore Seventy Four Lakh Eighty Three Thousand Six Hundred and Forty Eight";
    int[] num = new int[4];
    int first = 0;
    int u, h, t;
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    if (number < 0)
    {
    sb.Append("Minus ");
    number = -number;
    }
    string[] words0 = {"" ,"One ", "Two ", "Three ", "Four ",
    "Five " ,"Six ", "Seven ", "Eight ", "Nine "};
    string[] words1 = {"Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
    "Fifteen ","Sixteen ","Seventeen ","Eighteen ", "Nineteen "};
    string[] words2 = {"Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ",
    "Seventy ","Eighty ", "Ninety "};
    string[] words3 = { "Thousand ", "Lakh ", "Crore " };
    num[0] = number % 1000; // units
    num[1] = number / 1000;
    num[2] = number / 100000;
    num[1] = num[1] - 100 * num[2]; // thousands
    num[3] = number / 10000000; // crores
    num[2] = num[2] - 100 * num[3]; // lakhs
    for (int i = 3; i > 0; i--)
    {
    if (num[i] != 0)
    {
    first = i;
    break;
    }
    }
    for (int i = first; i >= 0; i--)
    {
    if (num[i] == 0) continue;
    u = num[i] % 10; // ones
    t = num[i] / 10;
    h = num[i] / 100; // hundreds
    t = t - 10 * h; // tens
    if (h > 0) sb.Append(words0[h] + "Hundred ");
    if (u > 0 || t > 0)
    {
    if (h > 0 || i == 0) sb.Append("and ");
    if (t == 0)
    sb.Append(words0[u]);
    else if (t == 1)
    sb.Append(words1[u]);
    else
    sb.Append(words2[t - 2] + words0[u]);
    }
    if (i != 0) sb.Append(words3[i - 1]);
    }
    return sb.ToString().TrimEnd();
    }

    Reference code:

    http://stackoverflow.com/questions/9156442/convert-amount-to-rupees-and-paise-in-words-format-in-c-sharp

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #764341
    Hai Navaneetha Krishnan,
    To convert too the specific format, you need to create a method will do the conversion things and then you can display the data.
    You need to create a method which will take the value as input and then it will parse that value to the word and will return the string.
    You can get many examples while searching in Google for the conversion to word but you need to modify it according to your requirements.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764458
    Hi,
    try this:
    string szAmount = "11.50";
    decimal dConverted = decimal.Parse(szAmount, CultureInfo.InvariantCulture);
    CultureInfo IndianCurrency = new CultureInfo("hi-IN");
    string szFinalOutput = string.Format(IndianCurrency, "{0:c}", dConverted);
    Console.WriteLine(szFinalOutput);
    //... OR you can also refer this:
    // http://www.codeproject.com/Articles/106122/Convert-Numeric-Currency-into-Words-For-INDIAN-Cur

    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments