string[] arr1 = new string[4] {"", " THOUSAND", " MILLION", " BILLION"}; string[] arr2 = new string[10] {"ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"}; string[] arr3 = new string[10] {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"}; string[] arr4 = new string[10] { "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN" };
# region 英文數字翻譯 private string Translate(string num) { double len=num.Length; int i,j=0; string strRet=""; double cols1=Math.Ceiling(len/3); int cols = SysConvert.ToInt32(cols1); double first1=len-cols1*3; int first = SysConvert.ToInt32(first1);
for(i=SysConvert.ToInt32( first);i<len;i+=3) { string num3 = ""; ++j; if(i>=0) { if (i + 3 < len) { num3 = num.Substring(i, 3); } else { num3 = num.Substring(i,SysConvert.ToInt32(len)-i); } } else { num3 = num.Substring(0, SysConvert.ToInt32(first) + 3); } string strEng=English(num3); if(strEng!="") { if(strRet!="") strRet+="," ;
strRet += English(num3) + arr1[SysConvert.ToInt32(cols) - j]; } } return strRet; } private string English( string num) { string strRet=""; if((num.Length==3)&&(num.Substring(0,3)!="000")) { if((num.Substring(0,1)!="0")) { strRet+=arr3[SysConvert.ToInt32( num.Substring(0,1))]+" HUNDRED"; if(num.Substring(1,2)!="00") strRet+=" AND "; } num=num.Substring(1); } if((num.Length==2)) { if((num.Substring(0,1)=="0")) { num = num.Substring(1); } else if ((num.Substring(0, 1) == "1")) { strRet += arr4[SysConvert.ToInt32(num.Substring(1, 1))]; } else { strRet += arr2[SysConvert.ToInt32(num.Substring(0, 1))]; if (num.Substring(1, 1) != "0") strRet+="-"; num = num.Substring(1); } } if ((num.Length == 1) && (num.Substring(0, 1) != "0")) { strRet += arr3[SysConvert.ToInt32(num.Substring(0, 1))]; } return strRet; } #endregion
整数部分转入Translate过程,第一位小数在Arr2中取,第二位小数在Arr3中取。
|
请发表评论