如何用C#语言编程小写金额转换大写金额?求高手解答……
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用C#语言编程小写金额转换大写金额?求高手解答……相关的知识,希望对你有一定的参考价值。
C#数字金额转换为大写中文金额代码如下:string NumberCn(double ANumber)
const string cPointCn = "点十百千万十百千亿十百千";
const string cNumberCn = "零一二三四五六七八九";
string S = ANumber.ToString();
if (S == "0") return "" + cPointCn[0];
if (!S.Contains(".")) S += ".";
int P = S.IndexOf(".");
string Result = "";
for (int i = 0; i < S.Length; i++)
if (P == i)
Result = Result.Replace("零十零", "零");
Result = Result.Replace("零百零", "零");
Result = Result.Replace("零千零", "零");
Result = Result.Replace("零十", "零");
Result = Result.Replace("零百", "零");
Result = Result.Replace("零千", "零");
Result = Result.Replace("零万", "万");
Result = Result.Replace("零亿", "亿");
Result = Result.Replace("亿万", "亿");
Result = Result.Replace("零点", "点");
else
if (P > i)
Result += "" + cNumberCn[S[i] - '0'] + cPointCn[P - i - 1];
else Result += "" + cNumberCn[S[i] - '0'];
if (Result.Substring(Result.Length - 1, 1) == "" + cPointCn[0])
Result = Result.Remove(Result.Length - 1); // 一点-> 一
if (Result[0] == cPointCn[0])
Result = cNumberCn[0] + Result; // 点三-> 零点三
if ((Result.Length > 1) && (Result[1] == cPointCn[1]) &&
(Result[0] == cNumberCn[1]))
Result = Result.Remove(0, 1); // 一十三-> 十三
return Result;
string MoneyCn(double ANumber)
if (ANumber == 0) return "零";
string Result = NumberCn(Math.Truncate(ANumber * 100) / 100);
Result = Result.Replace("一", "壹");
Result = Result.Replace("二", "贰");
Result = Result.Replace("三", "叁");
Result = Result.Replace("四", "肆");
Result = Result.Replace("五", "伍");
Result = Result.Replace("六", "陆");
Result = Result.Replace("七", "柒");
Result = Result.Replace("八", "捌");
Result = Result.Replace("九", "玖");
Result = Result.Replace("九", "玖");
Result = Result.Replace("十", "拾");
Result = Result.Replace("百", "佰");
Result = Result.Replace("千", "仟");
if (Result.Contains("点"))
int P = Result.IndexOf("点");
Result = Result.Insert(P + 3, "分");
Result = Result.Insert(P + 2, "角");
Result = Result.Replace("点", "圆");
Result = Result.Replace("角分", "角");
Result = Result.Replace("零分", "");
Result = Result.Replace("零角", "");
Result = Result.Replace("分角", "");
if (Result.Substring(0, 2) == "零圆")
Result = Result.Replace("零圆", "");
else Result += "圆整";
Result = "人民币" + Result;
return Result;
参考技术A 好吧,帮你写了个土方法花了一个小时调试···输入必须小于一万亿
public static string UpperAmount(double am)
if (am > 1000000000000)
return "overflow";
string ret = "";
short jiao = (short)((am * 10) % 10);
short fen = (short)((am * 100) % 10);
long yuan = (long)am % 10000;
long yuanW = (long)am / 10000 % 10000;
long yuanY = (long)am / 100000000;
string yuanS = KiloToUpper(yuan);
string yuanWS = KiloToUpper(yuanW);
string yuanYS = KiloToUpper(yuanY);
if (yuanY != 0)
ret += yuanYS + "亿";
if (yuanW != 0)
if (yuanW < 1000)
ret += "零" + yuanWS + "万";
else
ret += yuanWS + "万";
if (yuan != 0)
if (yuan < 1000)
ret += "零" + yuanS + "元";
else
ret += yuanS + "元";
else
ret += "元";
if (jiao != 0)
ret += NumToUpper(jiao) + "角";
else
ret += "零";
if (fen != 0)
ret += NumToUpper(fen) + "分";
return ret;
public static string KiloToUpper(long yuan)
string ret = "";
string tmp = "";
bool flag = false;
long yuanTmp = yuan;
for (int i = 0; i < yuan.ToString().Length; i++)
tmp = NumToUpper((short)(yuanTmp % 10));
if ((short)(yuanTmp % 10) != 0)
flag = false;
switch (i)
case 1:
ret = "拾" + ret;
break;
case 2:
ret = "佰" + ret;
break;
case 3:
ret = "千" + ret;
break;
else
if (!flag)
if(i > 0)
ret = tmp + ret;
flag = true;
yuanTmp /= 10;
continue;
yuanTmp /= 10;
ret = tmp + ret;
return ret;
public static string NumToUpper(short num)
string ret = "";
switch (num)
case 0:
ret = "零";
break;
case 1:
ret = "壹";
break;
case 2:
ret = "贰";
break;
case 3:
ret = "叁";
break;
case 4:
ret = "肆";
break;
case 5:
ret = "伍";
break;
case 6:
ret = "陆";
break;
case 7:
ret = "柒";
break;
case 8:
ret = "捌";
break;
case 9:
ret = "玖";
break;
return ret;
参考技术B 要个毛的高手。 自己写一个方法 分都没得。 参考技术C 收藏了
js怎么把数字金额转换为大写金额
参考技术A 百度一下这种写好的js很多 随便选个就可以;我帮你搜了个;function Arabia_to_Chinese(Num)
for(i=Num.length-1;i>=0;i--)
Num = Num.replace(",","")
Num = Num.replace(" ","")
Num = Num.replace("¥","")
if(isNaN(Num))
alert("请检查小写金额是否正确");
return;
part = String(Num).split(".");
newchar = "";
for(i=part[0].length-1;i>=0;i--)
if(part[0].length > 10) alert("位数过大,无法计算");return "";
tmpnewchar = ""
perchar = part[0].charAt(i);
switch(perchar)
case "0": tmpnewchar="零" + tmpnewchar ;break;
case "1": tmpnewchar="壹" + tmpnewchar ;break;
case "2": tmpnewchar="贰" + tmpnewchar ;break;
case "3": tmpnewchar="叁" + tmpnewchar ;break;
case "4": tmpnewchar="肆" + tmpnewchar ;break;
case "5": tmpnewchar="伍" + tmpnewchar ;break;
case "6": tmpnewchar="陆" + tmpnewchar ;break;
case "7": tmpnewchar="柒" + tmpnewchar ;break;
case "8": tmpnewchar="捌" + tmpnewchar ;break;
case "9": tmpnewchar="玖" + tmpnewchar ;break;
switch(part[0].length-i-1)
case 0: tmpnewchar = tmpnewchar +"元" ;break;
case 1: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
case 2: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
case 3: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
case 4: tmpnewchar= tmpnewchar +"万" ;break;
case 5: if(perchar!=0)tmpnewchar= tmpnewchar +"拾" ;break;
case 6: if(perchar!=0)tmpnewchar= tmpnewchar +"佰" ;break;
case 7: if(perchar!=0)tmpnewchar= tmpnewchar +"仟" ;break;
case 8: tmpnewchar= tmpnewchar +"亿" ;break;
case 9: tmpnewchar= tmpnewchar +"拾" ;break;
newchar = tmpnewchar + newchar;
if(Num.indexOf(".")!=-1)
if(part[1].length > 2)
part[1] = part[1].substr(0,2)
for(i=0;i<part[1].length;i++)
tmpnewchar = ""
perchar = part[1].charAt(i)
switch(perchar)
case "0": tmpnewchar="零" + tmpnewchar ;break;
case "1": tmpnewchar="壹" + tmpnewchar ;break;
case "2": tmpnewchar="贰" + tmpnewchar ;break;
case "3": tmpnewchar="叁" + tmpnewchar ;break;
case "4": tmpnewchar="肆" + tmpnewchar ;break;
case "5": tmpnewchar="伍" + tmpnewchar ;break;
case "6": tmpnewchar="陆" + tmpnewchar ;break;
case "7": tmpnewchar="柒" + tmpnewchar ;break;
case "8": tmpnewchar="捌" + tmpnewchar ;break;
case "9": tmpnewchar="玖" + tmpnewchar ;break;
if(i==0)tmpnewchar =tmpnewchar + "角";
if(i==1)tmpnewchar = tmpnewchar + "分";
newchar = newchar + tmpnewchar;
while(newchar.search("零零") != -1)
newchar = newchar.replace("零零", "零");
newchar = newchar.replace("零亿", "亿");
newchar = newchar.replace("亿万", "亿");
newchar = newchar.replace("零万", "万");
newchar = newchar.replace("零元", "元");
newchar = newchar.replace("零角", "");
newchar = newchar.replace("零分", "");
if (newchar.charAt(newchar.length-1) == "元" || newchar.charAt(newchar.length-1) == "角")
newchar = newchar+"整"
return newchar;
看了下没什么大问题本回答被提问者采纳
以上是关于如何用C#语言编程小写金额转换大写金额?求高手解答……的主要内容,如果未能解决你的问题,请参考以下文章