将数字转换成中文大小写、金额大小写
/// <summary> /// 将数字转换成中文大写 /// </summary> /// <param name="Value">数字</param> /// <param name="bToUpper">是否转换成汉字大写 true表示大写 false表示小写</param> /// <param name="bMoney">是否转换成金额格式 true表示金额格式 false表示普通格式</param> /// <returns></returns> public static string DataConvert(double Value, bool bToUpper = true, bool bMoney = true) { if (Value == 0 || Value > 999999999999.99) { if (Value == 0 && !bMoney) { return "零"; } else { return ""; } } string str = Value.ToString("F2"); string sLast = "";//小数点后面的数据 string fuhao = "";//负号 string[] Cnum = new string[10]; string[] Cbit = new string[12]; Cnum[0] = "零"; Cnum[1] = (bToUpper ? "壹" : "一"); Cnum[2] = (bToUpper ? "贰" : "二"); Cnum[3] = (bToUpper ? "叁" : "三"); Cnum[4] = (bToUpper ? "肆" : "四"); Cnum[5] = (bToUpper ? "伍" : "五"); Cnum[6] = (bToUpper ? "陆" : "六"); Cnum[7] = (bToUpper ? "柒" : "七"); Cnum[8] = (bToUpper ? "捌" : "八"); Cnum[9] = (bToUpper ? "玖" : "九"); Cbit[0] = ""; Cbit[1] = (bToUpper ? "拾" : "十"); Cbit[2] = (bToUpper ? "佰" : "百"); Cbit[3] = (bToUpper ? "仟" : "千"); Cbit[4] = "万"; Cbit[5] = (bToUpper ? "拾" : "十"); Cbit[6] = (bToUpper ? "佰" : "百"); Cbit[7] = (bToUpper ? "仟" : "千"); Cbit[8] = "亿"; Cbit[9] = (bToUpper ? "拾" : "十"); Cbit[10] = (bToUpper ? "佰" : "百"); Cbit[11] = (bToUpper ? "仟" : "千"); if (!bMoney) { string[] arrayValue = Value.ToString().Split(‘.‘); sLast = arrayValue.Length > 1 ? arrayValue[1] : ""; } if (Value < 0) { str = str.ToString().Remove(0, 1);//去掉负号 fuhao = "负"; } int MaxLen = str.Length; bool zoo = true; bool Needzoo = false; bool HaveWan = false; bool HaveYi = false; int tmpVal = 0; string[] strBit = new string[MaxLen]; string ConvertMoney = ""; int i = 0; for (i = 0; i < MaxLen; i++) { if (i != 2) { tmpVal = Convert.ToInt32(str.Substring(MaxLen - i - 1, 1)); } switch (i) { case 0: if (bMoney) { if (tmpVal != 0) { strBit[i] = Cnum[tmpVal] + "分"; } } break; case 1: if (bMoney) { if (tmpVal != 0) { strBit[i] = Cnum[tmpVal] + "角"; } } break; case 2: break; case 3: if (tmpVal != 0) { strBit[i] = Cnum[tmpVal] + (bMoney ? (bToUpper ? "圆" : "元") : ""); zoo = false; } else { Needzoo = true; if (MaxLen > 4) { strBit[3] = (bMoney ? (bToUpper ? "圆" : "元") : ""); } } if (strBit[1] == "" && strBit[0] != "" && strBit[3] != "") { strBit[i] = strBit[i] + "零"; } break; case 4: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "拾" : "十"); if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 5: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "佰" : "百"); if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 6: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "仟" : "千"); if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 7: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + "万"; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; HaveWan = true; } break; case 8: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "拾" : "十"); if (!HaveWan) { strBit[i] = strBit[i] + "万"; } HaveWan = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 9: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "佰" : "百"); if (!HaveWan) { strBit[i] = strBit[i] + "万"; } HaveWan = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 10: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "仟" : "千"); if (!HaveWan) { strBit[i] = strBit[i] + "万"; } HaveWan = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 11: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + "亿"; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; HaveYi = true; } break; case 12: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "拾" : "十"); if (!HaveYi) { strBit[i] = strBit[i] + "亿"; } HaveYi = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 13: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "佰" : "百"); if (!HaveYi) { strBit[i] = strBit[i] + "亿"; } HaveYi = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; case 14: if (tmpVal == 0) { Needzoo = true; } else { strBit[i] = Cnum[tmpVal] + (bToUpper ? "仟" : "千"); if (!HaveYi) { strBit[i] = strBit[i] + "亿"; } HaveYi = true; if (Needzoo) { if (zoo) { strBit[i] = (strBit[3] == "" ? strBit[i] + (bMoney ? (bToUpper ? "圆" : "元") : "") : strBit[i]); } else { strBit[i] = strBit[i] + "零"; } } zoo = false; Needzoo = false; } break; } } str = ""; for (i = MaxLen - 1; i >= 0; i--) { str = str + strBit[i]; } if (bMoney) { ConvertMoney = (str.Contains("分") ? fuhao + str : fuhao + str + "整"); } else { if ((int)Value == 0) { str = "零"; } if (sLast.Length > 0) { if (Convert.ToInt32(sLast) > 0) { str = str + "点"; for (i = 0; i < sLast.Length; i++) { str = str + Cnum[Convert.ToInt32(sLast.Substring(i, 1))]; } } } ConvertMoney = fuhao + str; } return ConvertMoney; }