using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.VisualBasic;


public partial class MoneyUpperWrite : System.Web.UI.Page
{
    private char[] bigChar = {''''''''''''''''''''};
    private char[] powerChar = { '''''''''亿''''''''''''''''''''' };
    private string[,] replaceStr = {{"零元"""}, 
                                   {"零拾"""},
                                   {"零佰"""},
                                   {"零仟"""},
                                   {"零万"""},
                                   {"零亿""亿"},
                                   {"亿万""亿"},
                                   {"零零零"""},
                                   {"零零"""},
                                   {"零万"""},
                                   {"零亿""亿"},
                                   {"亿万""亿"},
                                   {"零元"""},
                                   {"零角"""},
                                   {"零分"""},
                                   {"零整"""}}; 


    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Response.Write(NumToChar(Convert.ToDouble(TextBox1.Text)));

        TextBox2.Text = NumToChar(Convert.ToDouble(TextBox1.Text));
    }

    private string NumToChar(double Num)
    {
        string Money = string.Format("{0,15:0}", Num * 100);
        string Ret = "";
        for (int i = 0; i < 15; i++)
        {
            string tmpChar = Money.Substring(i, 1);
            if (tmpChar == " ")
            {
                continue;
            }
            else
            {
                Ret += bigChar[Convert.ToInt32(tmpChar)];
                Ret += powerChar[i];
            }
        }
        for (int i = 0; i < replaceStr.GetLength(0); i++)
        {
            Ret = Strings.Replace(Ret, replaceStr[i, 0], replaceStr[i, 1], 1, -1, CompareMethod.Text);
        }
        return Ret;
    }
}

 

posted on 2012-03-25 23:57  wzca  阅读(400)  评论(0)    收藏  举报