Pleasure resort of Gleam™

NumberToWord

Dev & Mng2005.05.18 10:27
[CODE]public static string N2W(double DouStr) { int inStr = (int)Math.Ceiling(DouStr); int iArrInStrCount = inStr.ToString("#,##0").Split(',').Length; string strTemp; string strReturnStr = string.Empty; string [] strModule = {"", "Thousand ", "Million ", "Billion ", "Trillion "}; string [] strOneIntStr = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}; string [] ArrInStr = inStr.ToString("#,##0").Split(','); for(int i = 0 ; i < iArrInStrCount ; i++ ){ int intStr = int.Parse(ArrInStr[i]); strTemp = ""; if(intStr > 99){ strTemp = strOneIntStr[(int)Math.Ceiling(intStr / 100)] + "Hundred "; } int intStr2 = intStr % 100; if(intStr2 > 9 && intStr2 < 20){ switch(intStr2){ case 10: strTemp += "Ten"; break; case 11: strTemp += "Eleven"; break; case 12: strTemp += "Twelve"; break; case 13: strTemp += "Thirteen"; break; case 14: strTemp += "Fourteen"; break; case 15: strTemp += "Fifteen"; break; case 16: strTemp += "Sixteen"; break; case 17: strTemp += "Seventeen"; break; case 18: strTemp += "Eighteen"; break; case 19: strTemp += "Nineteen"; break; } }else{ switch((int)Math.Ceiling(intStr2 / 10)){ case 2: strTemp += "Twenty "; break; case 3: strTemp += "Thirty "; break; case 4: strTemp += "Forty "; break; case 5: strTemp += "Fifty "; break; case 6: strTemp += "Sixty "; break; case 7: strTemp += "Seventy "; break; case 8: strTemp += "Eighty "; break; case 9: strTemp += "Ninety "; break; } switch(intStr2 % 10){ case 1: strTemp += "One"; break; case 2: strTemp += "Two"; break; case 3: strTemp += "Three"; break; case 4: strTemp += "Four"; break; case 5: strTemp += "Five"; break; case 6: strTemp += "Six"; break; case 7: strTemp += "Seven"; break; case 8: strTemp += "Eight"; break; case 9: strTemp += "Nine"; break; } } strReturnStr += strTemp + strModule[ArrInStr.Length - 1 - i]; } strReturnStr += string.Format(" and {0:00}/100",(int)Math.Ceiling((DouStr * 100) % 100)); return strReturnStr; }[/CODE]
From: Devpia.com

'Dev & Mng' 카테고리의 다른 글

ASP.NET ViewState값 제거하고 Submit하기  (0) 2005.05.19
NumberToWord  (0) 2005.05.18
프로그래머 십계명  (0) 2005.04.29
JS와 DIV를 이용한 탭브라우징  (0) 2005.04.26

Comment +0