2
Answers

Numeric values to alphabetical.

emmanuel okoh

emmanuel okoh

10y
688
1
Good morning my fellow programmers,Please can someone help me;

"I want to display my output result in words and in numeric,I did the numeric successfully but am find it difficult to do the words".

In the design view,I have 2 textboxes,I want one of them to display number(in figures) while the other one will display(numbers in words) words.


Thanks.

Answers (2)
0
Vulpes

Vulpes

NA 98.3k 1.5m 10y
Accepted
1
Niranjan Poddar

Niranjan Poddar

NA 308 39.7k 10y
try this........

 public static string ConvertNumbertoWords ( int number )
    {
        if ( number == 0 )
            return "Zero";
        if ( number < 0 )
            return "minus" + ConvertNumbertoWords ( Math.Abs ( number ) );

        string words = "";
        if ( ( number / 1000000 ) > 0 )
        {
            words += ConvertNumbertoWords ( number / 1000000 ) + " MILLION ";
            number %= 1000000;
        }
        if ( ( number / 1000 ) > 0 )
        {
            words += ConvertNumbertoWords ( number / 1000 ) + " THOUSAND ";
            number %= 1000;
        }
        if ( ( number / 100 ) > 0 )
        {
            words += ConvertNumbertoWords ( number / 100 ) + " HUNDRED ";
            number %= 100;
        }
        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;

    }
    protected void btnConvert_Click1 ( object sender, EventArgs e )
    {
        string word = ConvertNumbertoWords ( Convert.ToInt32 ( txtFig.Text ) );
        lblWord.Text = word;
    }