The following C # code enables the function of converting the Arab number into Chinese capital, and the Visual Studio.Net 2003 is basically passed (without strict testing, I hope that you will find errors, contact the author in contact Fanz2000@sohu.com, or directly in 9cbs Notify the last reply).
The code's master function is ConvertSum, and its parameters are the number string of the String type. In the ASP.NET, the mode is as follows: Label1.Text = ConvertSum ("Digital String");
The code is as follows:
@ OF: fanz2000 //Email:fanz2000@sohu.com /// /// main function converts a digital value (including decimals) /// summary> /// Digital string param> /// Converts a string after Chinese uppercase or an error message prompt string returns> public string converTsum (String Str) {if (! IspositportEcimal (STR)) Return "input Not a positive number! "; If (Double.Parse (STR)> 9999999999999.99) RETURN" The number is too large, can not be converted, please enter the amount below 10 billion yuan "; char [] ch = new char [1]; ch [0] = '.'; // Dadix String [] splitstr = null; // Defines the string array splitstr = Str.Split (CH [0]) by decimal point segmentation; // Press the decimal point segmentation IF ( Splitstr.length == 1) // Only the integer part Return ConvertData (STR) "round"; Else // has a fractional part {String RSTR; rstr = convertdata (splitstr [0]) "round"; // conversion Integer part RSTR = ConvertXiaoshu (splitstr [1]); // Converts the fractional part Return RSTR;}} /// // judgment is a positive number string /// summary> /// Judgment string param> /// If it is a number, return TRUE, otherwise return false returns> public bool ispositvedecimal (String str) {decimal D; try {d = decimal.Parse (STR);} Catch (Exception) {Return False;} f (d> 0) Return True; ELSE Return False;} /// /// Conversion Digital (integer) /// summary> /// Integer number string required to convert param> ///// Converts String (String Str) {String Tmpstr = "; String Rstr ="; INT Strlen = Str.length; INT STRLEN = Str.length; IF (Strlen <= 4) / / Digital length is less than four bits {RSTR = ConvertDigit (Str);} else {if (Strlen <= 8) // The number length is greater than four, less than eight bits {tmpstr =
Str.Substring (Strlen-4, 4); // First intercept the last four digit RSTR = ConvertDigit (tmpstr); // Convert the last four digits TMPSTR = Str.Substring (0, strlen-4); // Interception Number // Two converted numbers plus thousands of times RSTR = String.concat (CONVERTDIGIT (TMPSTR) "10,000", RSTR); RSTR = RSTR.Replace ("万", "10,000"); RSTR = rstr.replace ("zero zero", "zero");} else if (strlen <= 12) // number length is greater than eight, less than twelve {tmpstr = str.substring (Strlen-4, 4); // first intercept the last four digit RSTR = ConvertDigit (tmpstr); // Convert the last four digits tmpstr = str.substring (strllen-8, 4); // intercept four digits rstr = string.concat (ConvertDigit) TMPSTR) "10,000", RSTR); tmpstr = str.substring (0, strlish-8); rstr = string.concat (convertdigit (tmpstr) "100 million", RSTR = RSTR.Replace ("零"," 100 million "); rstr = rstr.replace (" 万 "," zero "); rstr = rstr.replace (" zero zero "," zero "); rstr = rstr.replace (" zero zero ", "Zero");}} Strlen = RSTR.LENGTH; if (strl.substring (Strlen-2, 2)) {Case "零": rstr = rstr.substring (0, Strlen -2) ""; break; case "zero": rstr = rstr.substring (0, strlen-2) "仟"; Break; Case "10,000": rstr = rstr.substring (0, Strlen -2) "10,000"; break; castr = rstr.substring (0, strlen-2) "Break;}}
Return RSTR;} /// /// Conversion Digital (decimal part) /// summary> /// Extra number of fractional numbers required to convert param> / // Converts the string after Chinese uppercase returns> public string converTxiaoshu (string str.length; string = str.length; string rstr; if (string == 1) {RSTR = ConvertCHINESE (STR) "Angle"; RETURN RSTR;} else {string tmpstr = str.substring (0,1); rstr = convertCHINESE (TMPSTR) "Corner"; tmpstr = str.substring (1, 1); RSTR = ConvertChinese (tmpstr) "Points"; rstr = rstr.replace ("zero", ""); rstr = rstr.replace ("zero", ""); return RSTR;}} /// /// conversion Number /// summary> /// Converted string (within four digits) param> /// returns> public string convertd (string str) { INT STRLEN = Str.Length; String Rstr = ""; Switch (Strlen) {case 1: RSTR = ConvertCHINESE (STR); Break; Case 2: rstr = convert2digit (str); break; case 3: rstr = Convert3Digit (STR) Break; case 4: rstr = convert4digit (str); Break;}}}}} ("pick zero", "pick"); strlen = rtr.length;
Return RSTR;
/// /// Conversion four digits /// summary> public string control4digit (string str) {string str1 = str.substring (0,1); string str2 = str.substring (1, 1 ); String str3 = str.substring (2, 1); string str4 = str.substring (3, 1); string = "; rstring = convertChinese (str1) " 仟 "; RString = ConvertChinese (STR2) ""; RString = ConvertChinese (STR3) "Pick"; RString = ConvertChinese (str4); rstring = rstring.replace ("zero", "zero"); rstring = rstring.replace ("Zero", " Zero "); rstring = rstring.replace (" Zero Pick "," Zero "); RString = rstring.replace (" zero zero "," zero "); rstring = rstring.replace (" zero zero "," zero " ); Rstring = rstring.replace ("zero zero", "zero"); return RString;} /// /// Translation three digits /// summary> public string control3digit (string str) { String str1 = str.substring (0,1); string str2 = str.substring (1, 1); string str3 = str.substring (2, 1); string = ""; rstring = convertCHINESE (STR1) " "; Rtring = convertChinese (STR2) " Pick "; RString = ConvertChinese (STR3); rstring = rstring.replace (" Zero "," Zero "); rstring = rstrin G.Replace ("Zero Pick", "Zero"); rstring = rstring.replace ("zero zero", "zero"); rstring = rstring.replace ("zero zero", "zero"); return rstring;} /// /// Conversion two digits /// summary> public string converT2digit (string str) {string str1 = str.substring (0,1); string str2 = str.substring (1, 1 String rstring = ""; rstring =