1.数字转换成汉字大写
public string NumToChinese(string x) { //数字转换为中文后的数组 string[] P_array_num = new string[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; //为数字位数建立一个位数组 string[] P_array_digit = new string[] { "", "拾", "佰", "仟" }; //为数字单位建立一个单位数组 string[] P_array_units = new string[] { "", "万", "亿", "万亿" }; string P_str_returnValue = ""; //返回值 int finger = 0; //字符位置指针 int P_int_m = x.Length % 4; //取模 int P_int_k = 0; if (P_int_m > 0) P_int_k = x.Length / 4 + 1; else P_int_k = x.Length / 4; //外层循环,四位一组,每组最后加上单位: ",万亿,",",亿,",",万," for (int i = P_int_k; i > 0; i--) { int P_int_L = 4; if (i == P_int_k && P_int_m != 0) P_int_L = P_int_m; //得到一组四位数 string four = x.Substring(finger, P_int_L); int P_int_l = four.Length; //内层循环在该组中的每一位数上循环 for (int j = 0; j < P_int_l; j++) { //处理组中的每一位数加上所在的位 int n = Convert.ToInt32(four.Substring(j, 1)); if (n == 0) { if (j < P_int_l - 1 && Convert.ToInt32(four.Substring(j + 1, 1)) > 0 && !P_str_returnValue.EndsWith(P_array_num[n])) P_str_returnValue += P_array_num[n]; } else { if (!(n == 1 && (P_str_returnValue.EndsWith(P_array_num[0]) | P_str_returnValue.Length == 0) && j == P_int_l - 2)) P_str_returnValue += P_array_num[n]; P_str_returnValue += P_array_digit[P_int_l - j - 1]; } } finger += P_int_L; //每组最后加上一个单位:",万,",",亿," 等 if (i < P_int_k) //如果不是最高位的一组 { if (Convert.ToInt32(four) != 0) //如果所有4位不全是0则加上单位",万,",",亿,"等 P_str_returnValue += P_array_units[i - 1]; } else { //处理最高位的一组,最后必须加上单位 P_str_returnValue += P_array_units[i - 1]; } } return P_str_returnValue; }
2.数值转换成汉字大写
public static string GetChinaMoney(decimal money) { string[] strArray; string str = ""; string str2 = ""; string str3 = money.ToString("0.00"); switch (str3.Trim().Length) { case 4: strArray = new string[] { str3[0].ToString(), "y", str3[2].ToString(), "j", str3[3].ToString(), "f" }; str = string.Concat(strArray); break; case 5: strArray = new string[] { str3[0].ToString(), "s", str3[1].ToString(), "y", str3[3].ToString(), "j", str3[4].ToString(), "f" }; str = string.Concat(strArray); break; case 6: strArray = new string[] { str3[0].ToString(), "b", str3[1].ToString(), "s", str3[2].ToString(), "y", str3[4].ToString(), "j", str3[5].ToString(), "f" }; str = string.Concat(strArray); break; case 7: strArray = new string[] { str3[0].ToString(), "q", str3[1].ToString(), "b", str3[2].ToString(), "s", str3[3].ToString(), "y", str3[5].ToString(), "j", str3[6].ToString(), "f" }; str = string.Concat(strArray); break; case 8: strArray = new string[] { str3[0].ToString(), "w", str3[1].ToString(), "q", str3[2].ToString(), "b", str3[3].ToString(), "s", str3[4].ToString(), "y", str3[6].ToString(), "j", str3[7].ToString(), "f" }; str = string.Concat(strArray); break; case 9: strArray = new string[] { str3[0].ToString(), "s", str3[1].ToString(), "w", str3[2].ToString(), "q", str3[3].ToString(), "b", str3[4].ToString(), "s", str3[5].ToString(), "y", str3[7].ToString(), "j", str3[8].ToString(), "f" }; str = string.Concat(strArray); break; case 10: strArray = new string[] { str3[0].ToString(), "b", str3[1].ToString(), "s", str3[2].ToString(), "w", str3[3].ToString(), "q", str3[4].ToString(), "b", str3[5].ToString(), "s", str3[6].ToString(), "y", str3[8].ToString(), "j", str3[9].ToString(), "f" }; str = string.Concat(strArray); break; case 11: strArray = new string[] { str3[0].ToString(), "q", str3[1].ToString(), "b", str3[2].ToString(), "s", str3[3].ToString(), "w", str3[4].ToString(), "q", str3[5].ToString(), "b", str3[6].ToString(), "s", str3[7].ToString(), "y", str3[9].ToString(), "j", str3[10].ToString(), "f" }; str = string.Concat(strArray); break; case 12: strArray = new string[] { str3[0].ToString(), "m", str3[1].ToString(), "q", str3[2].ToString(), "b", str3[3].ToString(), "s", str3[4].ToString(), "w", str3[5].ToString(), "q", str3[6].ToString(), "b", str3[7].ToString(), "s", str3[8].ToString(), "y", str3[10].ToString(), "j", str3[11].ToString(), "f" }; str = string.Concat(strArray); break; } for (int i = 0; i < str.Trim().Length; i++) { switch (str[i]) { case '0': str2 = str2 + "零"; break; case '1': str2 = str2 + "壹"; break; case '2': str2 = str2 + "贰"; break; case '3': str2 = str2 + "叁"; break; case '4': str2 = str2 + "肆"; break; case '5': str2 = str2 + "伍"; break; case '6': str2 = str2 + "陆"; break; case '7': str2 = str2 + "柒"; break; case '8': str2 = str2 + "捌"; break; case '9': str2 = str2 + "玖"; break; case 'b': str2 = str2 + "佰"; break; case 'f': str2 = str2 + "分"; break; case 'j': str2 = str2 + "角"; break; case 'm': str2 = str2 + "亿"; break; case 'q': str2 = str2 + "仟"; break; case 's': str2 = str2 + "拾"; break; case 'w': str2 = str2 + "万"; break; case 'y': str2 = str2 + "元"; break; } } return str2; }标签:case,string,C#,str2,汉字,str3,int,ToString,大写 From: https://www.cnblogs.com/SmallChen/p/16993873.html