asp.net 寫一個RMB金額大寫轉換器(原始碼)

c979170768發表於2011-11-08
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
                   
    }
    protected void Button1_Click(object sender, EventArgs e)
    {


        if (TextBox1.Text.Contains('.'))
        {
            string intzheng=TextBox1.Text.Substring(0, TextBox1.Text.LastIndexOf('.'));   //整數部分
            string intdot = TextBox1.Text.Substring(TextBox1.Text.LastIndexOf('.')+1);    //小數部分

            output(Convert.ToInt32(intzheng), 1);
            output(Convert.ToInt32(intdot),2);
            

        }
        else if (!TextBox1.Text.Contains('.'))
        {
            output(Convert.ToInt32(TextBox1.Text), 1);   //這裡是沒有小資料部分的
        }
        else
        {
            Response.Write("輸入有誤請重新輸入!");       //這裡是錯誤提示
        }

        Label1.Text = TextBox1.Text;

        //以上為整數部分
        //以下為小數部分
       

    }


    protected void output<T>(T int0,T signbin)
    {

        string[] num = new string[] { "零", "壹", "貳", "叄", "肆", "伍", "陸", "柒", "捌", "玖" };
       // string[] wei0 = new string[] { "釐", "分", "角" };
          string[] wei0 = new string[] { "角", "分", "釐" };
        string[] wei = new string[] { "元", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "萬" };
        string outputstring = "";         //這裡是串加器

        if (signbin.ToString() == "1")    //這裡整數部分
        {
            Stack<string> stack = new Stack<string>();
            int int1 = Convert.ToInt32(int0.ToString());   //分成整數部分
            int sign = 0;
            do
            {

                int s = int1 % 10;
                int1 = int1 / 10;

                stack.Push(wei[sign].ToString());
                stack.Push(num[s].ToString());
                sign++;

            } while (int1 > 0);

            foreach (string item in stack)
            {
                outputstring += item;
            }

            if (outputstring.Substring(1, 1) == "拾" && outputstring.Substring(0, 1) == "壹")
            {
                outputstring = outputstring.Substring(1);
            }
            Label2.Text = outputstring;
            //Response.Write(outputstring);
        }
        else if(signbin.ToString()=="2")
        {
           // Stack<string> stackdot = new Stack<string>();
            Queue<string> stackdot = new Queue<string>();
          //  int int2 = Convert.ToInt32(int0.ToString());
            string b = "";

            for (int i = int0.ToString().Length - 1; i >= 0; i--)
            {
                b += int0.ToString()[i];
            }

 

            int int2 = Convert.ToInt32(b);
            int singndot = 0;
            do
            {
                if (singndot >= 3)
                {
                    Response.Write("輸入的資料超出了最大數");
                    break;
                }
                int dot = int2 % 10;
                int2 = int2 / 10;

                //stackdot.Push(wei0[singndot]);
                //stackdot.Push(num[dot]);
               
                stackdot.Enqueue(num[dot]);
                stackdot.Enqueue(wei0[singndot]);


                singndot++;

            } while (int2 > 0);

            foreach (string item in stackdot)
            {
                outputstring += item;
            }

         // Response.Write(outputstring);
             Label2.Text += outputstring;
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string a = "123";
        //321 
        string b = "";
        for (int i = a.Length - 1; i >= 0; i--)
        {
            b += a[i];
        }
        Response.Write(b);
    }
}


 


 

相關文章