1.功能:完成金额从小写转为大写
2.输入参数:double 型数值。
3.输出参数:中文大写
4.如: 输入:7616.3
输出:柒仟陆佰壹拾陆元叁角整
输入:100567.05
输出:壹拾万零伍佰陆拾柒元零伍分用一个方法实现,谢谢!
2.输入参数:double 型数值。
3.输出参数:中文大写
4.如: 输入:7616.3
输出:柒仟陆佰壹拾陆元叁角整
输入:100567.05
输出:壹拾万零伍佰陆拾柒元零伍分用一个方法实现,谢谢!
解决方案 »
- 冰天雪地跪地求教
- 我想得到刚插入的数据的主键值,如果由于“并发”造成取得的不是最新的主键值怎么办?
- asp.net 表锁定的问题
- 求助 !!!! 一个关于使用模板后CheckBoxList 后台取值的问题
- Request.QueryString["Name"].ToString()为什么自动解码。。。?
- (分享)查询数据库,作为数据源的几种方法
- 未能加载文件或程序集“Microsoft.Office.Interop.Owc11, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”或它的某一个依赖项
- 很简单的一个问题!!!!!!!!!!!!解决马上给分!!!!!!!!!!!!
- 100分求一个用户控件的代码!顶者也有分!不够可以再加.
- log4net往SQL SERVER中写入数据
- 在线等:无法打开项目文件“E:\开发工作\VS.NET开发\temp.cjproj”
- 各位高手,问下Vs2005的asp.net的TreeView控件的事件
说明:CMoney.aspx页面省略,该页面有主要有三个Web Control控件,TextBoxt (id=txtNum),Button,Label(id=lblRet)文件名:CMoney.aspx.cs(CBMoney为主要函数)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace suanFa
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label lblRet;
protected System.Web.UI.WebControls.TextBox txtNum;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
string myNum=txtNum.Text;
lblRet.Visible=true;
//lblRet.ForeColor="#ff0000";
lblRet.Text="结果:"+CBMoney(myNum);
}
public string CBMoney(string num)
{
string zNum="",xNum="";
int dPos=num.IndexOf(".");
if (dPos>0)
{
zNum=num.Substring(0,dPos);
xNum=num.Substring(dPos+1);
}else
zNum=num;
string[] ArrMoney=new string[]{"零","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾"};
string[] ArrUnit=new string[]{"万","千","百","拾","元"};
string[] ArrXUnit=new string[]{"角","分"};
int lenZNum=zNum.Length;
string[] nArrUnit=new string[lenZNum];
int j=0;
for(int i=ArrUnit.Length-lenZNum;i<ArrUnit.Length;i++){
nArrUnit[j]=ArrUnit[i];
j++;
}
string strMoney="";
for(int i=0;i<zNum.Length;i++)
{
//char[] arrChar=num.ToCharArray();
string nChar=zNum.Substring(i,1);
strMoney=strMoney+ArrMoney[Int32.Parse(nChar)]+"<b>"+nArrUnit[i]+"</b>";
}
if(dPos>0)
{
for(int i=0;i<xNum.Length;i++)
{
string nChar=xNum.Substring(i,1);
strMoney=strMoney+ArrMoney[Int32.Parse(nChar)]+"<b>"+ArrXUnit[i]+"</b>";
}
}
return strMoney;
}
}
}
public static string GetThousandNumberName(string p_strThousandNumberName)
{
string v_strThousand = p_strThousandNumberName;
string v_strThousandNumberName = "";
if (v_strThousand.Length == 1)
v_strThousand = "000" + v_strThousand;
if (v_strThousand.Length == 2)
v_strThousand = "00" + v_strThousand;
if (v_strThousand.Length == 3)
v_strThousand = "0" + v_strThousand; for (int i = 0; i < v_strThousand.Length; i++)
{
if (i == 0 && Convert.ToInt32(v_strThousand[i].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString())) + "千";
if (i == 1 && Convert.ToInt32(v_strThousand[i].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString())) + "百";
else
if (i == 1 && Convert.ToInt32(v_strThousand[i - 1].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString()));
if (i == 2 && Convert.ToInt32(v_strThousand[i].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString()) * 10);
else
if (i == 2 && Convert.ToInt32(v_strThousand[i - 1].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString()));
if (i == 3 && Convert.ToInt32(v_strThousand[i].ToString()) > 0)
v_strThousandNumberName = v_strThousandNumberName + GetEngNumberName(Convert.ToInt32(v_strThousand[i].ToString()));
}
return v_strThousandNumberName;
}
public static string GetInvertingNumberName(string p_strIntNumberName)
{
string v_InvertingNumberName = "", v_IntNumberName = p_strIntNumberName;
for (int i = p_strIntNumberName.Length - 1; i >= 0; i--)
{
v_InvertingNumberName = v_InvertingNumberName + v_IntNumberName[i].ToString();
}
return v_InvertingNumberName;
} public static string GetEngNumberName(int p_intNumber)
{
string v_strEngNumberName = "";
switch (p_intNumber)
{
case 0:
v_strEngNumberName = "零";
break;
case 1:
v_strEngNumberName = "壹";
break;
case 2:
v_strEngNumberName = "贰";
break;
case 3:
v_strEngNumberName = "叁";
break;
case 4:
v_strEngNumberName = "肆";
break;
case 5:
v_strEngNumberName = "伍";
break;
case 6:
v_strEngNumberName = "陆";
break;
case 7:
v_strEngNumberName = "柒";
break;
case 8:
v_strEngNumberName = "捌";
break;
case 9:
v_strEngNumberName = "玖";
break;
case 10:
v_strEngNumberName = "壹拾";
break;
case 20:
v_strEngNumberName = "贰拾";
break;
case 30:
v_strEngNumberName = "叁拾";
break;
case 40:
v_strEngNumberName = "肆拾";
break;
case 50:
v_strEngNumberName = "伍拾";
break;
case 60:
v_strEngNumberName = "陆拾";
break;
case 70:
v_strEngNumberName = "柒拾";
break;
case 80:
v_strEngNumberName = "捌拾";
break;
case 90:
v_strEngNumberName = "玖拾";
break;
}
return v_strEngNumberName;
}
#endregion
'实现货币金额中文大写转换的程序
'程式限制为不可输入超过16个数字
Dim x As String, y As String
Const zimu = ".sbqwsbqysbqwsbq" '定义位置代码
Const letter = "0123456789sbqwy.zjf" '定义汉字缩写
Const upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿圆整角分" '定义大写汉字 If CDbl(money) >= 1E+16 Then daxie = "#VALUE!": Exit Function '只能转换一亿亿元以下数目的货币! x = Format(money, "0.00") '格式化货币
y = ""
For i = 1 To Len(x) - 3
y = y & Mid(x, i, 1) & Mid(zimu, Len(x) - 2 - i, 1)
Next
If Right(x, 3) = ".00" Then
y = y & "z" '***元整
Else
y = y & Left(Right(x, 2), 1) & "j" & Right(x, 1) & "f" '*元*角*分
End If
y = Replace(y, "0q", "0") '避免零千(如:40200肆万零千零贰佰)
y = Replace(y, "0b", "0") '避免零百(如:41000肆万壹千零佰)
y = Replace(y, "0s", "0") '避免零十(如:204贰佰零拾零肆) y = Replace(y, "0j", "0") '避免零角
y = Replace(y, "0f", "") '避免零分 Do While y <> Replace(y, "00", "0")
y = Replace(y, "00", "0") '避免双零(如:1004壹仟零零肆)
Loop
y = Replace(y, "0y", "y") '避免零亿(如:210亿 贰佰壹十零亿)
y = Replace(y, "0w", "w") '避免零万(如:210万 贰佰壹十零万)
y = IIf(x < 0.1, Right(y, Len(y) - 3), y) '避免零几分(如:0.01零壹分;0.04零肆分)
y = IIf(Len(x) = 5 And Left(y, 1) = "1", Right(y, Len(y) - 1), y) '避免壹十(如:14壹拾肆;10壹拾)
y = IIf(Len(x) = 4, Replace(y, "0.", ""), Replace(y, "0.", ".")) '避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分) For i = 1 To 19
y = Replace(y, Mid(letter, i, 1), Mid(upcase, i, 1)) '大写汉字
Next
daxie = y
End Function
a=FormatNumber(a,2,-1,0,0)
Dim String1 '如下定义
Dim String2 '如下定义
Dim String3 '从原A值中取出的值 Dim I '循环变量
Dim J 'A的值乘以100的字符串长度
Dim Ch1 '数字的汉语读法 Dim Ch2 '数字位的汉字读法
Dim nZero '用来计算连续的非零数是几个 If a=0 Then Exit Function
String1 = "零壹贰叁肆伍陆柒捌玖"
String2 = "万仟佰拾亿仟佰拾万仟佰拾元角分"
J = Len(CStr(a * 100))
String2 = Right(String2, J) '取出对应位数的STRING2的值 For I = 1 To J
String3 = Mid(a * 100, I, 1) '取出需转换的某一位的值 If String3 <> "0" Then
Ch1 = Mid(String1, Int(String3) + 1, 1)
Ch2 = Mid(String2, I, 1)
nZero = nZero + 1 '表示本位不为零 Else
If nZero <> 0 Or I = J - 9 Or I = J - 5 Or I = J - 1 Then
If Right(AtoC, 1) = "零" Then AtoC = Left(AtoC, Len(AtoC) - 1)
Ch1 = "零"
Else
Ch1 = ""
End If
'如果转换的数值需要扩大,那么需改动以下表达式 I 的值。 If I = J - 10 Then
Ch2 = "亿"
ElseIf I = J - 6 Then
If nZero <> 0 Then
Ch2 = "万"
'nZero = 0
End If
ElseIf I = J - 2 Then
Ch2 = "元"
ElseIf I = J Then
Ch2 = "整"
Else
Ch2 = ""
End If
nZero = 0
End If
AtoC = AtoC & Ch1 & Ch2
Next
AtoC = Replace(AtoC, "零元", "元")
AtoC = Replace(AtoC, "零万", "万")
AtoC = Replace(AtoC, "零亿", "亿")
AtoC = Replace(AtoC, "零整", "整")
End Function