分享
 
 
 

把金额类型转换成大写和英文

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

using System;

namespace ChangeMoney

{

/// <summary>

/// ChangeManage 的摘要说明。

/// </summary>

public class ChangeMoneyClass

{

public static string MoneytoEng(string n)

{

// string result="";

string m=getFloat(n);

string strfloat=" point"+m.Replace("0"," zero").Replace("1"," one").Replace("2"," two").Replace("3"," three").Replace("4"," four").Replace("5"," five").Replace("6"," six").Replace("7"," seven").Replace("8"," eight").Replace("9"," nine");

string []b=new string[6];

int i=0;

double t=double.Parse(n);

if (getInteger(n)=="0")

{

b[0]="zero";

}

// for (i=0;t>=1000.0;i++)

else

{

do

{

int k=int.Parse(getInteger(t.ToString()))%1000;

b[i]=getNum3(k);

t=t/1000.0;

if (int.Parse(getInteger(t.ToString()))<1000 & int.Parse(getInteger(t.ToString()))>0)

{

switch(i)

{

case 0:

if(k!=0)

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" thousand and "+b[i];

}

else

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" thousand "+b[i];

}

break;

case 1:

if(k!=0)

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" million and "+b[i];

}

else

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" million "+b[i];

}

break;

case 2:

if(k!=0)

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" billion and "+b[i];

}

else

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" billion "+b[i];

}

break;

case 3:

if(k!=0)

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" trillion and "+b[i];

}

else

{

b[i]=getNum3(int.Parse(getInteger(t.ToString())))+" trillion "+b[i];

}

break;

default:

b[i]=" the number is too large!!!";

break;

}

}

else if(int.Parse(getInteger(t.ToString()))>=1000)

{

switch(i)

{

case 0:

b[i]=" thousand "+b[i];

break;

case 1:

b[i]=" million "+b[i];

break;

case 2:

b[i]=" billion "+b[i];

break;

case 3:

b[i]=" trillion "+b[i];

break;

default:

b[i]=" the number is too large!!!";

break;

}

}

// while(i>=0)

// {

// result=result+b[i];

// i--;

// }

i++;

}while(t>=1000.0);

}

// return result;

return b[5]+b[4]+b[3]+b[2]+b[1]+b[0]+strfloat;

//0-999

}

private static string getNum3(int n)

{

string m=n.ToString();

string []b=new string[3];

string str="";

if(n>=100 & n<1000)

{

b[0]=m.Substring(0,1).Replace("0","").Replace("1","one hundred ").Replace("2","two hundred ").Replace("3","three hundred ").Replace("4","four hundred ").Replace("5","five hundred ").Replace("6","six hundred ").Replace("7","seven hundred ").Replace("8","eight hundred ").Replace("9","nine hundred ");

if(m.Substring(1,1)=="1")

{

str=m.Substring(1,2).Replace("10","and ten ").Replace("11","and eleven ").Replace("12","and twelve ").Replace("13","and thirteen ").Replace("14","and fourteen ").Replace("15","and fifteen ").Replace("16","and sixteen ").Replace("17","and seventeen ").Replace("18","and eighteen ").Replace("19","and nineteen ");

}

else if(m.Substring(1,1)=="0")

{

str=m.Substring(1,2).Replace("00","").Replace("01","and one ").Replace("02","and two ").Replace("03","and three ").Replace("04","and four ").Replace("05","and five ").Replace("06","and six ").Replace("07","and seven ").Replace("08","and eight ").Replace("09","and nine ");

}

else

{

b[1]=m.Substring(1,1).Replace("2","and twenty ").Replace("3","and thirty ").Replace("4","and forty ").Replace("5","and fifty ").Replace("6","and sixty ").Replace("7","and seventy ").Replace("8","and eighty ").Replace("9","and ninty ");

b[2]=m.Substring(2,1).Replace("0","").Replace("1","-one ").Replace("2","-two ").Replace("3","-three ").Replace("4","-four ").Replace("5","-five ").Replace("6","-six ").Replace("7","-seven ").Replace("8","-eight ").Replace("9","-nine ");

str=b[1]+b[2];

}

}

else if(n<100 & n>=10)

{

b[0]="";

if(m.Substring(0,1)=="1")

{

str=m.Substring(0,2).Replace("10","ten ").Replace("11","eleven ").Replace("12","twelve ").Replace("13","thirteen ").Replace("14","fourteen ").Replace("15","fifteen ").Replace("16","sixteen ").Replace("17","seventeen ").Replace("18","eighteen ").Replace("19","nineteen ");

}

else

{

b[1]=m.Substring(0,1).Replace("2","twenty ").Replace("3","thirty ").Replace("4","forty ").Replace("5","fifty ").Replace("6","sixty ").Replace("7","seventy ").Replace("8","eighty ").Replace("9","ninty ");

b[2]=m.Substring(1,1).Replace("0","").Replace("1","-one ").Replace("2","-two ").Replace("3","-three ").Replace("4","-four ").Replace("5","-five ").Replace("6","-six ").Replace("7","-seven ").Replace("8","-eight ").Replace("9","-nine ");

str=b[1]+b[2];

}

}

else if(n>=0 & n<10)

{

b[0]="";

b[1]="";

b[2]=m.Substring(0,1).Replace("0","").Replace("1"," one ").Replace("2"," two ").Replace("3"," three ").Replace("4"," four ").Replace("5"," five ").Replace("6"," six ").Replace("7"," seven ").Replace("8"," eight ").Replace("9"," nine ");

str=b[1]+b[2];

}

return b[0]+str;

}

private static string getInteger(string n)

{

string []a;

a=n.Split('.');

string s=a[0];

return s;

}

private static string getFloat(string n)

{

if(n.Replace("0","").Replace("1","").Replace("2","").Replace("3","").Replace("4","").Replace("5","").Replace("6","").Replace("7","").Replace("8","").Replace("9","")=="")

{

n=n+".0";

}

string []a;

a=n.Split('.');

string s=a[1];

return s;

}

public static string GetMoneyStr(double num)//总

{

try

{

string m_point="圆";

string m_sign;

int m_len;

//int g_max=20;

int g_dec=4;

string m_srcint;

string m_srcdec;

string m_retv="";

int m_cntr=0;

string m_decstr;

if(num>=0.00)

{

m_sign="";

}

else

{

m_sign="负";

num=num*(-1);

}

m_srcint=num.ToString().Trim();//m_srcint--"5658626456.235"

string[] s_cut=m_srcint.Split(new char[] {'.'});

if(s_cut.Length==2)

{

if(s_cut[0].ToString().Trim().Length>15)

{

m_retv=m_sign+m_retv+m_srcint+"转换失败!";

return m_retv;

}

if(s_cut[1].ToString().Trim().Length>4)

{

m_srcint=m_srcint.Substring(0,m_srcint.Length-(s_cut[1].ToString().Trim().Length-4));

}

}

else if(s_cut.Length==1)

{

m_srcint=m_srcint+".0000";

}

else

{

return num.ToString()+"转换失败!";

}

s_cut=m_srcint.Split(new char[] {'.'},2);

m_srcdec=s_cut[1].ToString().Trim();

m_srcdec=m_srcdec+"0000";

m_srcdec=m_srcdec.Substring(0,4);

m_srcint=s_cut[0].ToString().Trim();

m_len=m_srcint.Length;

string m_chr,m_last="",m_this="",m_cnzero=Num2cn("0"),m_cnname,m_lbase,m_tbase=Len2cnbase(m_len);

m_lbase=m_tbase;

for(m_cntr=1;m_cntr<=m_len;m_cntr++)

{

m_chr=m_srcint.Substring(m_cntr-1,1);

m_this=Num2cn(m_chr);

m_cnname=Len2cnname(m_len-m_cntr+1);

m_tbase=Len2cnbase(m_len-m_cntr+1);

if(m_lbase==m_tbase)

{

if(m_last==m_cnzero && m_this==m_cnzero)

{}

else

{

if((m_this==m_cnzero))

m_retv=m_retv+m_this+"";

else

m_retv=m_retv+m_this+m_cnname;

}

}

else

{

if(m_retv.Length>=2)

{

if(m_retv.Substring(m_retv.Length-2,2)==m_cnzero)

{

m_retv=m_retv.Substring(0,m_retv.Length-2);

m_last="";

}

}

m_retv=m_retv+m_lbase;

if(m_last==m_cnzero && m_this==m_cnzero)

{}

else

{

if((m_this==m_cnzero))

m_retv=m_retv+m_this+"";

else

m_retv=m_retv+m_this+m_cnname;

}

}

m_lbase=m_tbase;

m_last=m_this;

}

if(m_retv.Length-2>=0)

{

if(m_retv.Substring(m_retv.Length-2,2)==m_cnzero)

{

m_retv=m_retv.Substring(0,m_retv.Length-2);

}

}

m_retv=m_retv+m_point;

m_decstr="";

if(double.Parse(m_srcdec)==0)

{

if(m_point=="圆")

m_retv=m_retv+"整";

else

m_retv=m_retv+"";

}

else

{

m_len=g_dec;

m_this="";

m_last="";

for(m_cntr=m_len;m_cntr>0;m_cntr--)

{

m_chr=m_srcdec.Substring(m_cntr-1,1);

m_this=Num2cn(m_chr);

if(m_point=="圆")

{

m_cnname=Jedec(m_cntr);

if(m_this==m_cnzero && null==m_decstr)

{}

else

{

if(m_last==m_cnzero && m_this==m_cnzero)

{}

else

{

if(m_this==m_cnzero)

m_decstr=m_this+""+m_decstr;

else

m_decstr=m_this+m_cnname+m_decstr;

}

}

}

else

{

m_cnname="";

if(m_this==m_cnzero && null==m_decstr)

{}

else

m_decstr=m_this+m_decstr;

}

m_last=m_this;

}

}

string myretu=m_sign+m_retv+m_decstr;

if(myretu.Substring(myretu.Length-1,1)=="零")

return myretu.Substring(0,myretu.Length-1);

else

return myretu;

}

catch

{

return num.ToString()+"转换失败!";

}

}

#region 1--"角" 2--"分"

private static string Jedec(int num)

{

string retu="";

switch(num)

{

case 1:

retu="角";

break;

case 2:

retu="分";

break;

case 3:

retu="厘";

break;

case 4:

retu="毫";

break;

default:

retu="";

break;

}

return retu;

}

#endregion

#region cn >=14 && cn<=19--"兆"

private static string Len2cnbase(int cn)

{

string retu="";

if(cn>=14 && cn<=19)

{

retu="兆";

}

else if(cn>=9 && cn<=13)

{

retu="亿";

}

else if(cn>=5 && cn<=8)

{

retu="万";

}

else if(cn<5)

{

retu="";

}

else

{

retu="N/A";

}

return retu;

}

#endregion

#region 1--"",2--"拾"

private static string Len2cnname(int len)

{

string retu="";

switch(len)

{

case 1:

retu="";

break;

case 2:

retu="拾";

break;

case 3:

retu="佰";

break;

case 4:

retu="仟";

break;

case 5:

retu="";

break;

case 6:

retu="拾";

break;

case 7:

retu="佰";

break;

case 8:

retu="仟";

break;

case 9:

retu="";

break;

case 10:

retu="拾";

break;

case 11:

retu="佰";

break;

case 12:

retu="仟";

break;

case 13:

retu="万";

break;

case 14:

retu="";

break;

case 15:

retu="拾";

break;

case 16:

retu="佰";

break;

default:

retu="N/A";

break;

}

return retu;

}

#endregion

#region "0"--"零" 1--"壹"

private static string Num2cn(string numchr)

{

string retu="";

switch(numchr)

{

case "0":

retu="零";

break;

case "1":

retu="壹";

break;

case "2":

retu="贰";

break;

case "3":

retu="叁";

break;

case "4":

retu="肆";

break;

case "5":

retu="伍";

break;

case "6":

retu="陆";

break;

case "7":

retu="柒";

break;

case "8":

retu="捌";

break;

case "9":

retu="玖";

break;

default :

retu=numchr;

break;

}

return retu;

}

#endregion

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有