Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

[HELP] Guys about assembly language convert number to word

medievil

The Patriot
Advanced Member
Messages
693
Reaction score
0
Points
26
Guys sino po may assembly language dito ngayon or dati baka po may naitabi kayo na code for converting Number to Word.

For example: Ang range ay 0 - 99 then pagka run nung prog Input a number so ilalagay ko po is example ay 20 then pagka enter ang result ay Twenty.

:pray:
 
Ano ba programming language mo.. ito sa C#..

Code:
public static string NumberToWords(int number)
{
    if (number == 0)
        return "zero";

    if (number < 0)
        return "minus " + NumberToWords(Math.Abs(number));

    string words = "";

    if ((number / 1000000) > 0)
    {
        words += NumberToWords(number / 1000000) + " million ";
        number %= 1000000;
    }

    if ((number / 1000) > 0)
    {
        words += NumberToWords(number / 1000) + " thousand ";
        number %= 1000;
    }

    if ((number / 100) > 0)
    {
        words += NumberToWords(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;
}

how to use:

Code:
// HOW TO USE FUNCTION:
// Replace 'insert number here' with your desired number.
// string = NumbertoWords('insert number here');
// EXAMPLE:

string ntw = NumbertoWords(100);
MessageBox.Show(ntw);

// Shows a message box of text
// One Hundred.
// With new variable

// ------------------------------------------------

MessageBox.Show(NumberToWords(100));
// Shows a message box of text
// One Hundred.
// Without creating new variable.

that's it :)
 
Back
Top Bottom