asp.net 转换人民币方法

来源:互联网 发布:delphi是不是编程语言 编辑:程序博客网 时间:2024/06/06 03:22




code

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Text.RegularExpressions;namespace jquerytest.test2{    public partial class WebForm1 : System.Web.UI.Page    {        protected void Page_Load(object sender, EventArgs e)        {                    }        /// <summary>        /// 转换人民币大小金额(如果没有小数 人民币 带整字)         /// </summary>        /// <param name="rmb">阿拉伯数字</param>        /// <returns>人民币</returns>        public string GetMoney(double rmb)        {            string str = rmb.ToString("#L#E#D#C#K#E#D#C#J#E#D#C#I#E#D#C#H#E#D#C#G#E#D#C#F#E#D#C#.0B0A");            string rmbRegex = Regex.Replace(str, @"((?<=-|^)[^1-9]*)|((?'z'0)[0A-E]*((?=[1-9])|(?'-z'(?=[F-L\.]|$))))|((?'b'[F-L])(?'z'0)[0A-L]*((?=[1-9])|(?'-z'(?=[\.]|$))))", "${b}${z}");            string value = Regex.Replace(rmbRegex, ".", delegate(Match m)            { return "负元空零壹贰叁肆伍陆柒捌玖空空空空空空空分角拾佰仟万億兆京垓秭穰"[m.Value[0] - '-'].ToString(); });            return rmb == Convert.ToInt32(rmb) ? value + "整" : value;        }        protected void Button1_Click(object sender, EventArgs e)        {           Response.Write(GetMoney(Convert.ToDouble(TextBox1.Text)));        }    }}

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="jquerytest.test2.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <div>            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />        </div>    </form></body></html>



原创粉丝点击