欢迎光临
我们一直在努力

把金额类型转换成大写和英文-.NET教程,评论及其它

建站超值云服务器,限时71元/月

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

}

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 把金额类型转换成大写和英文-.NET教程,评论及其它
分享到: 更多 (0)

相关推荐

  • 暂无文章