asp.net 写一个RMB金额大写转换器(源码)

 
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);
    }
}


 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值