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

    How to Convert in this Screnario

    Hi

    How to create function Decimal to words. - (Sql Server )

    I need following output this



    --823456.21
    --Eight Lakh Twenty Three Thousand Four Hundread Fifty Six and Twenty one Paise Only

  • #768531
    Hi,

    We have do it by own coding. Initially we need to check how many integers are there given, based on that we need to pass the values.


    public string ConvertDecimaltoWords(long number)
    {
    if (number == 0) return "ZERO";
    if (number < 0) return "minus " + ConvertDecimaltoWords(Math.Abs(number));
    string words = "";

    if ((number / 100000000) > 0)
    {
    words += ConvertDecimaltoWords(number / 10000000) + " CRORES";
    number %= 10000000;
    }


    if ((number / 100000) > 0)
    {
    words += ConvertDecimaltoWords(number / 100000) + " LAKHS";
    number %= 1000000;
    }
    if ((number / 1000) > 0)
    {
    words += ConvertDecimaltoWords(number / 1000) + " THOUSANDS";
    number %= 1000;
    }
    if ((number / 100) > 0)
    {
    words += ConvertDecimaltoWords(number / 100) + " HUNDREDS";
    number %= 100;
    }
    if ((number / 10) > 0)
    {
    words += ConvertDecimaltoWords(number / 10) + " RUPEES ";
    number %= 10;
    }
    if (number > 0)
    {
    if (words != "") words += "AND ";
    var unitsMap = new[]
    {
    "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"
    };
    var tensMap = new[]
    {
    "ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"
    };
    if (number < 20) words += unitsMap[number];
    else
    {
    words += tensMap[number / 10];
    if ((number % 10) > 0) words += " " + unitsMap[number % 10];
    }
    }
    return words;
    }



    Thanks,
    Mani


  • Sign In to post your comments