dharmendar-dot / Dharam-dot

0 stars 0 forks source link

Spell the Number #1

Closed dharmendar-dot closed 4 years ago

dharmendar-dot commented 4 years ago

Please write code which takes a whole number and spells it out in words. For instance if 13456 is input it should be spelled as “thirteen thousand four hundred and fifty six”. The developer could choose to spell it out as international numbering system.

dharmendar-dot commented 4 years ago

1- .NET visual studio 2010 platform using for Spell to Number coding. compress .zip folder as below link- SpellTheNumber.zip

2- soft code also available for Problem Statement 1 : Spell the Number as below-

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;

namespace SpellTheNumber { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    public static string NoToSpell(int noDigit)
    {
        if (noDigit == 0)
            return "zero";

        if (noDigit < 0)
            return "minus " + NoToSpell(Math.Abs(noDigit));

        string words = "";

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

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

        if ((noDigit / 100) > 0)
        {
            words += NoToSpell(noDigit / 100) + " hundred ";
            noDigit %= 100;
        }

        if (noDigit > 0)
        {
            if (words != "")
                words += "and ";

            var unitsPlace = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
            var tensPlace = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

            if (noDigit < 20)
                words += unitsPlace[noDigit];
            else
            {
                words += tensPlace[noDigit / 10];
                if ((noDigit % 10) > 0)
                    words += "-" + unitsPlace[noDigit % 10];
            }
        }

        return words;
    }

    private void btnConvert_Click(object sender, EventArgs e)
    {
        txtWord.Text = NoToSpell(Convert.ToInt32(txtNumber.Text));
    }
}

}

dharmendar-dot commented 4 years ago

Resolved the issue by coding on .net platform.