日期:2014-05-18 浏览次数:20484 次
private string numberToEnglish(decimal y) { string numberStr=""; string lStr="";//小数点左边字符串 string rStr="";//小数点右边字符串 numberStr = (string) y.ToString(); int dot;//小数点位置 dot = numberStr.IndexOf("."); if (dot!= 0 & dot !=-1)//判断有没有小数 { lStr=numberStr.Substring(0,dot);//取小数点left的字串 if (numberStr.Substring(dot+1,2)=="00") { rStr=""; } else { rStr=numberStr.Substring(dot+1,2);//取小数点right的字串 } } else { lStr=numberStr;//没有小数点的情况 } string lStrRev; lStrRev=reverseString(lStr);//对左边的字串取反字串 string [] a= new string[5];//定义5个字串变量用来存放解析出的三位一组的字串 switch(lStrRev.Length % 3) { case 1: lStrRev = lStrRev + "00";break; case 2: lStrRev = lStrRev + "0";break; } string StrInt;//用来存放转换后的整数部分 StrInt=""; for(int i=0;i<=lStrRev.Length/3 -1;i++)//计算有多少个三位 { a[i]=reverseString(lStrRev.Substring(3*i,3));//截取第1个三位 if (a[i] != "000")//用来避免这种情况“1000000=ONE MILLION THOUSAND ONLY” { if (i!=0) { StrInt=w3(a[i]) + " " + dw(i.ToString()) + " " + StrInt;//用来加上“THOUSAND OR MILLION OR BILLION” } else { StrInt=w3(a[i]);//防止i=0时“lm=w3(a(i))+" "+dw(i)+" "+lm”多加两个尾空格 } } else { StrInt=w3(a[i]) + StrInt; } } string StrDce;//用来存放转换后的小数部分 StrDce=""; if ( dot != 0 & dot != -1 & rStr != "") { rStr="0" + rStr; StrDce=" AND POINT " + w2(rStr); } return StrInt + StrDce; } //将字符串反置 private string reverseString(string str) { int lenInt=str.Length; string [] z= new string [str.Length]; for(int i=0;i<lenInt;i++) { z[i]=str.Substring(i,1); } str=""; for (int i=lenInt-1;i>=0;i--) { str=str+z[i]; } return str; } private string zr4(string y) { string[] z= new string [10]; z[1]="ONE"; z[2]="TWO"; z[3]="THREE"; z[4]="FOUR"; z[5]="FIVE"; z[6]="SIX"; z[7]="SEVEN"; z[8]="EIGHT"; z[9]="NINE"; return z[Int32.Parse(y.Substring(0,1))]; } private string zr3(string y) { string[] z= new string [10]; z[1]="ONE"; z[2]="TWO"; z[3]="THREE"; z[4]="FOUR"; z[5]="FIVE"; z[6]="SIX"; z[7]="SEVEN"; z[8]="EIGHT"; z[9]="NINE"; return z[Int32.Parse(y.Substring(2,1))]; } private string zr2(string y) { string[] z= new string [20]; z[10]="TEN"; z[11]="ELEVEN"; z[12]="TWELVE"; z[13]="THIRTEEN"; z[14]="FOURTEEN"; z[15]="FIFTEEN"; z[16]="SIXTEEN"; z[17]="SEVENTEEN"; z[18]="EIGHTEEN"; z[19]="NINETEEN"; return z[Int32.Parse(y.Substring(1,2))]; } private string zr1(string y) { string[] z= new string [10]; z[1]="TEN"; z[2]="TWENTY"; z[3]="THIRTY"; z[4]="FORTY"; z[5]="FIFTY"; z[6]="SIXTY"; z[7]="SEVENTY"; z[8]="EIGHTY"; z[9]="NINETY"; return z[Int32.Parse(y.Substring(1,1))]; } private string dw(string y) { string[] z= new string[5]; z[0]=""; z[1]="THOUSAND"; z[2]="MILLION"; z[3]="BILLION"; return z[Int32.Parse(y)]; } //用来制作2位数字转英文 private string w2(string y) {