使用c#中的按钮将金额转换为单词

时间:2015-02-27 06:36:35

标签: c#

我创建了一个程序来转换单词的数量。它工作正常,最高可达99999金额值。无法转换其他数字而且不允许分数。任何人都可以帮我解决这个问题吗?以下是我的代码:

    private void button1_Click(object sender, EventArgs e)
    {
        string[] Ones = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
        string[] Tens = { "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
        string[] oo = { "Hundred", "Two Hundred", "Three Hundred", "Four Hundred", "Five Hundred", "Six Hundred", "Seven Hundred", "Eight Hundred", "Nine Hundred" };
        string[] Hundreds = { "one hundred thousand ", "two hundred thousand ", "three hundred ", "Four hundred", "Five hundred", "Six hundred", "Seven hundred", "Eight hundred", "Nine Hundred" };


        int no = int.Parse(textBox3.Text);
        string strWords = "";
        if (no > 99999 && no < 1000000)
        {
            int i = no / 100000;
            strWords = strWords + oo[i - 1] + "";
            no = no % 100000;
        }

        if (no > 99999 && no < 1000000)
        {
            int i = no / 100000;
            strWords = strWords + Hundreds[i - 1] + "";
            no = no % 100000;
        }

        if (no > 9999 && no < 100000)
        {
            int i = no / 10000;
            strWords = strWords + Tens[i - 1] + " ";
            no = no % 10000;
        }

        if (no > 999 && no < 10000)
        {
            int i = no / 1000;
            strWords = strWords + Ones[i - 1] + " Thousand ";
            no = no % 1000;
        }


        if (no > 99 && no < 1000)
        {
            int i = no / 100;
            strWords = strWords + Ones[i - 1] + " Hundred ";
            no = no % 100;
        }

        if (no > 19 && no < 100)
        {
            int i = no / 10;
            strWords = strWords + Tens[i - 1] + " ";
            no = no % 10;
        }

        if (no > 0 && no < 20)
        {
            strWords = strWords + Ones[no - 1];
        }

        textBox4.Text = strWords + " only"; 
    }

0 个答案:

没有答案